Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 1 | #include <string> |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 2 | #include <experimental/filesystem> |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 3 | #include <fstream> |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 4 | #include <phosphor-logging/log.hpp> |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 5 | #include <xyz/openbmc_project/Software/Version/server.hpp> |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 6 | #include "version.hpp" |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 7 | #include "config.h" |
| 8 | #include "item_updater.hpp" |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 9 | #include "activation.hpp" |
Michael Tritz | 60bc20f | 2017-07-29 23:32:21 -0500 | [diff] [blame] | 10 | #include "serialize.hpp" |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 11 | |
| 12 | namespace openpower |
| 13 | { |
| 14 | namespace software |
| 15 | { |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 16 | namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 17 | { |
| 18 | |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 19 | // When you see server:: you know we're referencing our base class |
| 20 | namespace server = sdbusplus::xyz::openbmc_project::Software::server; |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 21 | namespace fs = std::experimental::filesystem; |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 22 | |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 23 | using namespace phosphor::logging; |
| 24 | |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 25 | constexpr auto squashFSImage = "pnor.xz.squashfs"; |
| 26 | |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 27 | void ItemUpdater::createActivation(sdbusplus::message::message& m) |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 28 | { |
Patrick Williams | e429094 | 2017-06-16 05:43:08 -0500 | [diff] [blame] | 29 | using SVersion = server::Version; |
| 30 | using VersionPurpose = SVersion::VersionPurpose; |
| 31 | namespace msg = sdbusplus::message; |
| 32 | namespace variant_ns = msg::variant_ns; |
| 33 | |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 34 | sdbusplus::message::object_path objPath; |
| 35 | std::map<std::string, |
Patrick Williams | e429094 | 2017-06-16 05:43:08 -0500 | [diff] [blame] | 36 | std::map<std::string, msg::variant<std::string>>> interfaces; |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 37 | m.read(objPath, interfaces); |
Patrick Williams | e429094 | 2017-06-16 05:43:08 -0500 | [diff] [blame] | 38 | |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 39 | std::string path(std::move(objPath)); |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 40 | std::string filePath; |
Patrick Williams | e429094 | 2017-06-16 05:43:08 -0500 | [diff] [blame] | 41 | auto purpose = VersionPurpose::Unknown; |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 42 | std::string version; |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 43 | |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 44 | for (const auto& intf : interfaces) |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 45 | { |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 46 | if (intf.first == VERSION_IFACE) |
| 47 | { |
| 48 | for (const auto& property : intf.second) |
| 49 | { |
| 50 | if (property.first == "Purpose") |
| 51 | { |
| 52 | // Only process the Host and System images |
Patrick Williams | e429094 | 2017-06-16 05:43:08 -0500 | [diff] [blame] | 53 | auto value = SVersion::convertVersionPurposeFromString( |
| 54 | variant_ns::get<std::string>(property.second)); |
| 55 | |
| 56 | if (value == VersionPurpose::Host || |
| 57 | value == VersionPurpose::System) |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 58 | { |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 59 | purpose = value; |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 60 | } |
| 61 | } |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 62 | else if (property.first == "Version") |
| 63 | { |
Patrick Williams | e429094 | 2017-06-16 05:43:08 -0500 | [diff] [blame] | 64 | version = variant_ns::get<std::string>(property.second); |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 65 | } |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 66 | } |
| 67 | } |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 68 | else if (intf.first == FILEPATH_IFACE) |
| 69 | { |
| 70 | for (const auto& property : intf.second) |
| 71 | { |
| 72 | if (property.first == "Path") |
| 73 | { |
Patrick Williams | e429094 | 2017-06-16 05:43:08 -0500 | [diff] [blame] | 74 | filePath = variant_ns::get<std::string>(property.second); |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
Patrick Williams | e429094 | 2017-06-16 05:43:08 -0500 | [diff] [blame] | 79 | if ((filePath.empty()) || (purpose == VersionPurpose::Unknown)) |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 80 | { |
| 81 | return; |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 82 | } |
| 83 | |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 84 | // Version id is the last item in the path |
| 85 | auto pos = path.rfind("/"); |
| 86 | if (pos == std::string::npos) |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 87 | { |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 88 | log<level::ERR>("No version id found in object path", |
| 89 | entry("OBJPATH=%s", path)); |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | auto versionId = path.substr(pos + 1); |
| 94 | |
| 95 | if (activations.find(versionId) == activations.end()) |
| 96 | { |
| 97 | // Determine the Activation state by processing the given image dir. |
| 98 | auto activationState = server::Activation::Activations::Invalid; |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 99 | if (ItemUpdater::validateSquashFSImage(filePath) == 0) |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 100 | { |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 101 | activationState = server::Activation::Activations::Ready; |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 102 | } |
| 103 | |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 104 | fs::path manifestPath(filePath); |
| 105 | manifestPath /= MANIFEST_FILE; |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 106 | std::string extendedVersion = (Version::getValue(manifestPath.string(), |
| 107 | std::map<std::string, std::string> |
| 108 | {{"extended_version", ""}})).begin()->second; |
Gunnar Mills | 3edb84b | 2017-08-18 15:13:15 -0500 | [diff] [blame] | 109 | |
| 110 | // Create an association to the host inventory item |
| 111 | AssociationList associations{(std::make_tuple( |
| 112 | ACTIVATION_FWD_ASSOCIATION, |
| 113 | ACTIVATION_REV_ASSOCIATION, |
| 114 | HOST_INVENTORY_PATH))}; |
| 115 | |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 116 | activations.insert(std::make_pair( |
| 117 | versionId, |
| 118 | std::make_unique<Activation>( |
| 119 | bus, |
| 120 | path, |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 121 | *this, |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 122 | versionId, |
| 123 | extendedVersion, |
Gunnar Mills | 3edb84b | 2017-08-18 15:13:15 -0500 | [diff] [blame] | 124 | activationState, |
| 125 | associations))); |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 126 | versions.insert(std::make_pair( |
| 127 | versionId, |
| 128 | std::make_unique<Version>( |
| 129 | bus, |
| 130 | path, |
| 131 | version, |
| 132 | purpose, |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 133 | filePath, |
| 134 | *this))); |
Saqib Khan | 00044f4 | 2017-07-10 17:24:43 -0500 | [diff] [blame] | 135 | } |
Saqib Khan | 3fb2d17 | 2017-08-07 12:14:03 -0500 | [diff] [blame] | 136 | else |
| 137 | { |
| 138 | log<level::INFO>("Software Object with the same version already exists", |
Gunnar Mills | 3fa7028 | 2017-08-18 15:30:42 -0500 | [diff] [blame] | 139 | entry("VERSION_ID=%s", versionId)); |
Saqib Khan | 3fb2d17 | 2017-08-07 12:14:03 -0500 | [diff] [blame] | 140 | } |
Patrick Williams | 3accb32 | 2017-05-30 16:29:52 -0500 | [diff] [blame] | 141 | return; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 142 | } |
| 143 | |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 144 | void ItemUpdater::processPNORImage() |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 145 | { |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 146 | // Read pnor.toc from folders under /media/ |
| 147 | // to get Active Software Versions. |
Gunnar Mills | 3fa7028 | 2017-08-18 15:30:42 -0500 | [diff] [blame] | 148 | for (const auto& iter : fs::directory_iterator(MEDIA_DIR)) |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 149 | { |
| 150 | auto activationState = server::Activation::Activations::Active; |
| 151 | |
| 152 | static const auto PNOR_RO_PREFIX_LEN = strlen(PNOR_RO_PREFIX); |
| 153 | |
| 154 | // Check if the PNOR_RO_PREFIX is the prefix of the iter.path |
| 155 | if (0 == iter.path().native().compare(0, PNOR_RO_PREFIX_LEN, |
| 156 | PNOR_RO_PREFIX)) |
| 157 | { |
| 158 | auto pnorTOC = iter.path() / PNOR_TOC_FILE; |
| 159 | if (!fs::is_regular_file(pnorTOC)) |
| 160 | { |
| 161 | log<level::ERR>("Failed to read pnorTOC\n", |
| 162 | entry("FileName=%s", pnorTOC.string())); |
| 163 | activationState = server::Activation::Activations::Invalid; |
| 164 | } |
| 165 | auto keyValues = |
| 166 | Version::getValue(pnorTOC, |
| 167 | {{ "version", "" }, |
| 168 | { "extended_version", "" } }); |
| 169 | auto& version = keyValues.at("version"); |
| 170 | if (version.empty()) |
| 171 | { |
| 172 | log<level::ERR>("Failed to read version from pnorTOC", |
| 173 | entry("FILENAME=%s", pnorTOC.string())); |
| 174 | activationState = server::Activation::Activations::Invalid; |
| 175 | } |
| 176 | |
| 177 | auto& extendedVersion = keyValues.at("extended_version"); |
| 178 | if (extendedVersion.empty()) |
| 179 | { |
| 180 | log<level::ERR>("Failed to read extendedVersion from pnorTOC", |
| 181 | entry("FILENAME=%s", pnorTOC.string())); |
| 182 | activationState = server::Activation::Activations::Invalid; |
| 183 | } |
| 184 | |
| 185 | // The versionId is extracted from the path |
| 186 | // for example /media/pnor-ro-2a1022fe |
| 187 | auto id = iter.path().native().substr(PNOR_RO_PREFIX_LEN); |
| 188 | auto purpose = server::Version::VersionPurpose::Host; |
| 189 | auto path = fs::path(SOFTWARE_OBJPATH) / id; |
| 190 | |
Gunnar Mills | 3edb84b | 2017-08-18 15:13:15 -0500 | [diff] [blame] | 191 | |
| 192 | // Create an association to the host inventory item |
| 193 | AssociationList associations{(std::make_tuple( |
| 194 | ACTIVATION_FWD_ASSOCIATION, |
| 195 | ACTIVATION_REV_ASSOCIATION, |
| 196 | HOST_INVENTORY_PATH))}; |
| 197 | |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 198 | // Create Activation instance for this version. |
| 199 | activations.insert(std::make_pair( |
| 200 | id, |
| 201 | std::make_unique<Activation>( |
| 202 | bus, |
| 203 | path, |
| 204 | *this, |
| 205 | id, |
| 206 | extendedVersion, |
Gunnar Mills | 3edb84b | 2017-08-18 15:13:15 -0500 | [diff] [blame] | 207 | activationState, |
| 208 | associations))); |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 209 | |
| 210 | // If Active, create RedundancyPriority instance for this version. |
| 211 | if (activationState == server::Activation::Activations::Active) |
| 212 | { |
Michael Tritz | 3641792 | 2017-08-04 14:00:29 -0500 | [diff] [blame] | 213 | uint8_t priority = std::numeric_limits<uint8_t>::max(); |
| 214 | if (!restoreFromFile(id, priority)) |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 215 | { |
Michael Tritz | 3641792 | 2017-08-04 14:00:29 -0500 | [diff] [blame] | 216 | log<level::ERR>("Unable to restore priority from file.", |
Gunnar Mills | 3fa7028 | 2017-08-18 15:30:42 -0500 | [diff] [blame] | 217 | entry("VERSIONID=%s", id)); |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 218 | } |
Michael Tritz | 3641792 | 2017-08-04 14:00:29 -0500 | [diff] [blame] | 219 | activations.find(id)->second->redundancyPriority = |
| 220 | std::make_unique<RedundancyPriority>( |
| 221 | bus, |
| 222 | path, |
| 223 | *(activations.find(id)->second), |
| 224 | priority); |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | // Create Version instance for this version. |
| 228 | versions.insert(std::make_pair( |
| 229 | id, |
| 230 | std::make_unique<Version>( |
| 231 | bus, |
| 232 | path, |
| 233 | version, |
| 234 | purpose, |
| 235 | "", |
| 236 | *this))); |
| 237 | } |
| 238 | } |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 239 | return; |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 240 | } |
| 241 | |
Adriana Kobylak | 5ba6b10 | 2017-05-19 09:41:27 -0500 | [diff] [blame] | 242 | int ItemUpdater::validateSquashFSImage(const std::string& filePath) |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 243 | { |
Saqib Khan | 4c5d744 | 2017-07-18 00:43:52 -0500 | [diff] [blame] | 244 | auto file = fs::path(filePath) / squashFSImage; |
| 245 | if (fs::is_regular_file(file)) |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 246 | { |
| 247 | return 0; |
| 248 | } |
| 249 | else |
| 250 | { |
| 251 | log<level::ERR>("Failed to find the SquashFS image."); |
| 252 | return -1; |
| 253 | } |
| 254 | } |
| 255 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 256 | void ItemUpdater::removeReadOnlyPartition(std::string versionId) |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 257 | { |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 258 | auto serviceFile = "obmc-flash-bios-ubiumount-ro@" + versionId + |
| 259 | ".service"; |
| 260 | |
| 261 | // Remove the read-only partitions. |
| 262 | auto method = bus.new_method_call( |
| 263 | SYSTEMD_BUSNAME, |
| 264 | SYSTEMD_PATH, |
| 265 | SYSTEMD_INTERFACE, |
| 266 | "StartUnit"); |
| 267 | method.append(serviceFile, "replace"); |
| 268 | bus.call_noreply(method); |
| 269 | } |
| 270 | |
| 271 | void ItemUpdater::removeReadWritePartition(std::string versionId) |
| 272 | { |
| 273 | auto serviceFile = "obmc-flash-bios-ubiumount-rw@" + versionId + |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 274 | ".service"; |
| 275 | |
| 276 | // Remove the read-write partitions. |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 277 | auto method = bus.new_method_call( |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 278 | SYSTEMD_BUSNAME, |
| 279 | SYSTEMD_PATH, |
| 280 | SYSTEMD_INTERFACE, |
| 281 | "StartUnit"); |
| 282 | method.append(serviceFile, "replace"); |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 283 | bus.call_noreply(method); |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 284 | } |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 285 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 286 | void ItemUpdater::removePreservedPartition() |
| 287 | { |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 288 | // Remove the preserved partition. |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 289 | auto method = bus.new_method_call( |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 290 | SYSTEMD_BUSNAME, |
| 291 | SYSTEMD_PATH, |
| 292 | SYSTEMD_INTERFACE, |
| 293 | "StartUnit"); |
| 294 | method.append("obmc-flash-bios-ubiumount-prsv.service", "replace"); |
Adriana Kobylak | d6a549e | 2017-05-10 16:23:01 -0500 | [diff] [blame] | 295 | bus.call_noreply(method); |
Michael Tritz | dd961b6 | 2017-05-17 14:07:03 -0500 | [diff] [blame] | 296 | |
| 297 | return; |
| 298 | } |
| 299 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 300 | void ItemUpdater::reset() |
| 301 | { |
Gunnar Mills | 3fa7028 | 2017-08-18 15:30:42 -0500 | [diff] [blame] | 302 | for (const auto& it : activations) |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 303 | { |
| 304 | removeReadWritePartition(it.first); |
Michael Tritz | 60bc20f | 2017-07-29 23:32:21 -0500 | [diff] [blame] | 305 | removeFile(it.first); |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 306 | } |
| 307 | removePreservedPartition(); |
| 308 | return; |
| 309 | } |
| 310 | |
Saqib Khan | b8e7f31 | 2017-08-12 10:24:10 -0500 | [diff] [blame] | 311 | void ItemUpdater::freePriority(uint8_t value, const std::string& versionId) |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 312 | { |
| 313 | //TODO openbmc/openbmc#1896 Improve the performance of this function |
| 314 | for (const auto& intf : activations) |
| 315 | { |
Gunnar Mills | 3fa7028 | 2017-08-18 15:30:42 -0500 | [diff] [blame] | 316 | if (intf.second->redundancyPriority) |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 317 | { |
Saqib Khan | b8e7f31 | 2017-08-12 10:24:10 -0500 | [diff] [blame] | 318 | if (intf.second->redundancyPriority.get()->priority() == value && |
| 319 | intf.second->versionId != versionId) |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 320 | { |
Gunnar Mills | 3fa7028 | 2017-08-18 15:30:42 -0500 | [diff] [blame] | 321 | intf.second->redundancyPriority.get()->priority(value + 1); |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
Saqib Khan | 2af5c49 | 2017-07-17 16:15:13 -0500 | [diff] [blame] | 327 | bool ItemUpdater::isLowestPriority(uint8_t value) |
| 328 | { |
| 329 | for (const auto& intf : activations) |
| 330 | { |
Gunnar Mills | 3fa7028 | 2017-08-18 15:30:42 -0500 | [diff] [blame] | 331 | if (intf.second->redundancyPriority) |
Saqib Khan | 2af5c49 | 2017-07-17 16:15:13 -0500 | [diff] [blame] | 332 | { |
| 333 | if (intf.second->redundancyPriority.get()->priority() < value) |
| 334 | { |
| 335 | return false; |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | return true; |
| 340 | } |
| 341 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 342 | void ItemUpdater::erase(std::string entryId) |
| 343 | { |
Saqib Khan | ef8cd9f | 2017-08-16 14:20:30 -0500 | [diff] [blame] | 344 | // Remove priority persistence file |
| 345 | removeFile(entryId); |
| 346 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 347 | // Removing partitions |
| 348 | removeReadWritePartition(entryId); |
| 349 | removeReadOnlyPartition(entryId); |
| 350 | |
| 351 | // Removing entry in versions map |
| 352 | auto it = versions.find(entryId); |
| 353 | if (it == versions.end()) |
| 354 | { |
| 355 | log<level::ERR>(("Error: Failed to find version " + entryId + \ |
Gunnar Mills | 3fa7028 | 2017-08-18 15:30:42 -0500 | [diff] [blame] | 356 | " in item updater versions map." \ |
| 357 | " Unable to remove.").c_str()); |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 358 | return; |
| 359 | } |
| 360 | versions.erase(entryId); |
| 361 | |
| 362 | // Removing entry in activations map |
| 363 | auto ita = activations.find(entryId); |
| 364 | if (ita == activations.end()) |
| 365 | { |
| 366 | log<level::ERR>(("Error: Failed to find version " + entryId + \ |
Gunnar Mills | 3fa7028 | 2017-08-18 15:30:42 -0500 | [diff] [blame] | 367 | " in item updater activations map." \ |
| 368 | " Unable to remove.").c_str()); |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 369 | return; |
| 370 | } |
| 371 | activations.erase(entryId); |
| 372 | } |
| 373 | |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 374 | // TODO: openbmc/openbmc#1402 Monitor flash usage |
| 375 | void ItemUpdater::freeSpace() |
| 376 | { |
| 377 | std::size_t count = 0; |
| 378 | decltype(activations.begin()->second->redundancyPriority.get()->priority()) |
| 379 | highestPriority = 0; |
| 380 | decltype(activations.begin()->second->versionId) highestPriorityVersion; |
| 381 | for (const auto& iter : activations) |
| 382 | { |
| 383 | if (iter.second.get()->activation() == server::Activation::Activations::Active) |
| 384 | { |
| 385 | count++; |
| 386 | if (iter.second->redundancyPriority.get()->priority() > highestPriority) |
| 387 | { |
| 388 | highestPriority = iter.second->redundancyPriority.get()->priority(); |
| 389 | highestPriorityVersion = iter.second->versionId; |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | // Remove the pnor version with highest priority since the PNOR |
| 394 | // can't hold more than 2 versions. |
| 395 | if (count >= ACTIVE_PNOR_MAX_ALLOWED) |
| 396 | { |
| 397 | erase(highestPriorityVersion); |
| 398 | } |
| 399 | } |
| 400 | |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame^] | 401 | void ItemUpdater::createActiveAssociation(std::string path) |
| 402 | { |
| 403 | assocs.emplace_back(std::make_tuple(ACTIVE_FWD_ASSOCIATION, |
| 404 | ACTIVE_REV_ASSOCIATION, |
| 405 | path)); |
| 406 | associations(assocs); |
| 407 | } |
| 408 | |
| 409 | void ItemUpdater::removeActiveAssociation(std::string path) |
| 410 | { |
| 411 | for (auto iter = assocs.begin(); iter != assocs.end();) |
| 412 | { |
| 413 | if ((std::get<2>(*iter)).compare(path) == 0) |
| 414 | { |
| 415 | iter = assocs.erase(iter); |
| 416 | associations(assocs); |
| 417 | } |
| 418 | else |
| 419 | { |
| 420 | ++iter; |
| 421 | } |
| 422 | } |
| 423 | } |
| 424 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 425 | } // namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 426 | } // namespace software |
| 427 | } // namespace openpower |