Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | #include "bcd_time.hpp" |
Matt Spinler | 8d5f3a2 | 2020-07-07 10:30:33 -0500 | [diff] [blame] | 3 | #include "paths.hpp" |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 4 | #include "pel.hpp" |
| 5 | |
| 6 | #include <algorithm> |
Matt Spinler | 0ff0048 | 2019-11-06 16:19:46 -0600 | [diff] [blame] | 7 | #include <bitset> |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 8 | #include <filesystem> |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 9 | #include <map> |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 10 | |
| 11 | namespace openpower |
| 12 | { |
| 13 | namespace pels |
| 14 | { |
| 15 | |
| 16 | /** |
| 17 | * @class Repository |
| 18 | * |
| 19 | * The class handles saving and retrieving PELs on the BMC. |
| 20 | */ |
| 21 | class Repository |
| 22 | { |
| 23 | public: |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 24 | /** |
Matt Spinler | 0ff0048 | 2019-11-06 16:19:46 -0600 | [diff] [blame] | 25 | * @brief Structure of commonly used PEL attributes. |
| 26 | */ |
| 27 | struct PELAttributes |
| 28 | { |
| 29 | std::filesystem::path path; |
Matt Spinler | dd325c3 | 2020-07-07 11:01:54 -0500 | [diff] [blame] | 30 | size_t sizeOnDisk; |
| 31 | uint8_t creator; |
| 32 | uint8_t severity; |
Matt Spinler | 0ff0048 | 2019-11-06 16:19:46 -0600 | [diff] [blame] | 33 | std::bitset<16> actionFlags; |
Matt Spinler | 346f99a | 2019-11-21 13:06:35 -0600 | [diff] [blame] | 34 | TransmissionState hostState; |
| 35 | TransmissionState hmcState; |
Matt Spinler | 0ff0048 | 2019-11-06 16:19:46 -0600 | [diff] [blame] | 36 | |
| 37 | PELAttributes() = delete; |
| 38 | |
Matt Spinler | dd325c3 | 2020-07-07 11:01:54 -0500 | [diff] [blame] | 39 | PELAttributes(const std::filesystem::path& p, size_t size, |
| 40 | uint8_t creator, uint8_t sev, uint16_t flags, |
Matt Spinler | 346f99a | 2019-11-21 13:06:35 -0600 | [diff] [blame] | 41 | TransmissionState hostState, TransmissionState hmcState) : |
| 42 | path(p), |
Matt Spinler | dd325c3 | 2020-07-07 11:01:54 -0500 | [diff] [blame] | 43 | sizeOnDisk(size), creator(creator), severity(sev), |
Matt Spinler | 346f99a | 2019-11-21 13:06:35 -0600 | [diff] [blame] | 44 | actionFlags(flags), hostState(hostState), hmcState(hmcState) |
Matt Spinler | 0ff0048 | 2019-11-06 16:19:46 -0600 | [diff] [blame] | 45 | { |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | /** |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 50 | * @brief A structure that holds both the PEL and corresponding |
| 51 | * OpenBMC IDs. |
| 52 | * Used for correlating the IDs with their data files for quick |
| 53 | * lookup. To find a PEL based on just one of the IDs, just use |
| 54 | * the constructor that takes that ID. |
| 55 | */ |
| 56 | struct LogID |
| 57 | { |
| 58 | struct Pel |
| 59 | { |
| 60 | uint32_t id; |
| 61 | explicit Pel(uint32_t i) : id(i) |
| 62 | { |
| 63 | } |
| 64 | }; |
| 65 | struct Obmc |
| 66 | { |
| 67 | uint32_t id; |
| 68 | explicit Obmc(uint32_t i) : id(i) |
| 69 | { |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | Pel pelID; |
| 74 | |
| 75 | Obmc obmcID; |
| 76 | |
| 77 | LogID(Pel pel, Obmc obmc) : pelID(pel), obmcID(obmc) |
| 78 | { |
| 79 | } |
| 80 | |
| 81 | explicit LogID(Pel id) : pelID(id), obmcID(0) |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | explicit LogID(Obmc id) : pelID(0), obmcID(id) |
| 86 | { |
| 87 | } |
| 88 | |
| 89 | LogID() = delete; |
| 90 | |
| 91 | /** |
| 92 | * @brief A == operator that will match on either ID |
| 93 | * being equal if the other is zero, so that |
| 94 | * one can look up a PEL with just one of the IDs. |
| 95 | */ |
| 96 | bool operator==(const LogID& id) const |
| 97 | { |
| 98 | if (id.pelID.id != 0) |
| 99 | { |
| 100 | return id.pelID.id == pelID.id; |
| 101 | } |
| 102 | if (id.obmcID.id != 0) |
| 103 | { |
| 104 | return id.obmcID.id == obmcID.id; |
| 105 | } |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | bool operator<(const LogID& id) const |
| 110 | { |
| 111 | return pelID.id < id.pelID.id; |
| 112 | } |
| 113 | }; |
| 114 | |
Matt Spinler | b0a8df5 | 2020-07-07 14:41:06 -0500 | [diff] [blame] | 115 | using AttributesReference = |
| 116 | std::reference_wrapper<const std::pair<const LogID, PELAttributes>>; |
| 117 | |
Matt Spinler | b188f78 | 2020-07-07 11:18:12 -0500 | [diff] [blame] | 118 | /** |
| 119 | * @brief A structure for keeping a breakdown of the sizes of PELs |
| 120 | * of different types in the repository. |
| 121 | */ |
| 122 | struct SizeStats |
| 123 | { |
| 124 | uint64_t total; |
| 125 | uint64_t bmc; |
| 126 | uint64_t nonBMC; |
| 127 | uint64_t bmcServiceable; |
| 128 | uint64_t bmcInfo; |
| 129 | uint64_t nonBMCServiceable; |
| 130 | uint64_t nonBMCInfo; |
| 131 | |
| 132 | SizeStats() : |
| 133 | total(0), bmc(0), nonBMC(0), bmcServiceable(0), bmcInfo(0), |
| 134 | nonBMCServiceable(0), nonBMCInfo(0) |
| 135 | { |
| 136 | } |
| 137 | }; |
| 138 | |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 139 | Repository() = delete; |
| 140 | ~Repository() = default; |
| 141 | Repository(const Repository&) = default; |
| 142 | Repository& operator=(const Repository&) = default; |
| 143 | Repository(Repository&&) = default; |
| 144 | Repository& operator=(Repository&&) = default; |
| 145 | |
| 146 | /** |
| 147 | * @brief Constructor |
| 148 | * |
| 149 | * @param[in] basePath - the base filesystem path for the repository |
| 150 | */ |
Matt Spinler | 8d5f3a2 | 2020-07-07 10:30:33 -0500 | [diff] [blame] | 151 | Repository(const std::filesystem::path& basePath) : |
| 152 | Repository(basePath, getPELRepoSize(), getMaxNumPELs()) |
| 153 | { |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * @brief Constructor that takes the repository size |
| 158 | * |
| 159 | * @param[in] basePath - the base filesystem path for the repository |
| 160 | * @param[in] repoSize - The maximum amount of space to use for PELs, |
| 161 | * in bytes |
| 162 | * @param[in] maxNumPELs - The maximum number of PELs to allow |
| 163 | */ |
| 164 | Repository(const std::filesystem::path& basePath, size_t repoSize, |
| 165 | size_t maxNumPELs); |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 166 | |
| 167 | /** |
| 168 | * @brief Adds a PEL to the repository |
| 169 | * |
| 170 | * Throws File.Error.Open or File.Error.Write exceptions on failure |
| 171 | * |
| 172 | * @param[in] pel - the PEL to add |
| 173 | */ |
| 174 | void add(std::unique_ptr<PEL>& pel); |
| 175 | |
| 176 | /** |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 177 | * @brief Removes a PEL from the repository |
| 178 | * |
Matt Spinler | 52602e3 | 2020-07-15 12:37:28 -0500 | [diff] [blame] | 179 | * Note that the returned LogID is the fully filled in LogID, i.e. |
| 180 | * it has both the PEL and OpenBMC IDs, unlike the passed in LogID |
| 181 | * which can just have one or the other. |
| 182 | * |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 183 | * @param[in] id - the ID (either the pel ID, OBMC ID, or both) to remove |
Matt Spinler | 52602e3 | 2020-07-15 12:37:28 -0500 | [diff] [blame] | 184 | * |
| 185 | * @return std::optional<LogID> - The LogID of the removed PEL |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 186 | */ |
Matt Spinler | 52602e3 | 2020-07-15 12:37:28 -0500 | [diff] [blame] | 187 | std::optional<LogID> remove(const LogID& id); |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 188 | |
| 189 | /** |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 190 | * @brief Generates the filename to use for the PEL ID and BCDTime. |
| 191 | * |
| 192 | * @param[in] pelID - the PEL ID |
| 193 | * @param[in] time - the BCD time |
| 194 | * |
| 195 | * @return string - A filename string of <BCD_time>_<pelID> |
| 196 | */ |
| 197 | static std::string getPELFilename(uint32_t pelID, const BCDTime& time); |
| 198 | |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 199 | /** |
| 200 | * @brief Returns true if the PEL with the specified ID is in the repo. |
| 201 | * |
| 202 | * @param[in] id - the ID (either the pel ID, OBMC ID, or both) |
| 203 | * @return bool - true if that PEL is present |
| 204 | */ |
| 205 | inline bool hasPEL(const LogID& id) |
| 206 | { |
Matt Spinler | 0ff0048 | 2019-11-06 16:19:46 -0600 | [diff] [blame] | 207 | return findPEL(id) != _pelAttributes.end(); |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 208 | } |
| 209 | |
Matt Spinler | 2813f36 | 2019-07-19 12:45:28 -0500 | [diff] [blame] | 210 | /** |
| 211 | * @brief Returns the PEL data based on its ID. |
| 212 | * |
| 213 | * If the data can't be found for that ID, then the optional object |
| 214 | * will be empty. |
| 215 | * |
| 216 | * @param[in] id - the LogID to get the PEL for, which can be either a |
| 217 | * PEL ID or OpenBMC log ID. |
| 218 | * @return std::optional<std::vector<uint8_t>> - the PEL data |
| 219 | */ |
| 220 | std::optional<std::vector<uint8_t>> getPELData(const LogID& id); |
| 221 | |
Matt Spinler | 6d51224 | 2019-12-09 13:44:17 -0600 | [diff] [blame] | 222 | /** |
| 223 | * @brief Get a file descriptor to the PEL data |
| 224 | * |
| 225 | * @param[in] id - The ID to get the FD for |
| 226 | * |
| 227 | * @return std::optional<sdbusplus::message::unix_fd> - |
| 228 | * The FD, or an empty optional object. |
| 229 | */ |
| 230 | std::optional<sdbusplus::message::unix_fd> getPELFD(const LogID& id); |
| 231 | |
Matt Spinler | 1ea7880 | 2019-11-01 13:04:59 -0500 | [diff] [blame] | 232 | using ForEachFunc = std::function<bool(const PEL&)>; |
| 233 | |
| 234 | /** |
| 235 | * @brief Run a user defined function on every PEL in the repository. |
| 236 | * |
| 237 | * ForEachFunc takes a const PEL reference, and should return |
| 238 | * true to stop iterating and return out of for_each. |
| 239 | * |
| 240 | * For example, to save up to 100 IDs in the repo into a vector: |
| 241 | * |
| 242 | * std::vector<uint32_t> ids; |
| 243 | * ForEachFunc f = [&ids](const PEL& pel) { |
| 244 | * ids.push_back(pel.id()); |
| 245 | * return ids.size() == 100 ? true : false; |
| 246 | * }; |
| 247 | * |
| 248 | * @param[in] func - The function to run. |
| 249 | */ |
| 250 | void for_each(ForEachFunc func) const; |
| 251 | |
Matt Spinler | 421f653 | 2019-11-06 15:40:45 -0600 | [diff] [blame] | 252 | using AddCallback = std::function<void(const PEL&)>; |
| 253 | |
| 254 | /** |
| 255 | * @brief Subscribe to PELs being added to the repository. |
| 256 | * |
| 257 | * Every time a PEL is added to the repository, the provided |
| 258 | * function will be called with the new PEL as the argument. |
| 259 | * |
| 260 | * The function must be of type void(const PEL&). |
| 261 | * |
| 262 | * @param[in] name - The subscription name |
| 263 | * @param[in] func - The callback function |
| 264 | */ |
| 265 | void subscribeToAdds(const std::string& name, AddCallback func) |
| 266 | { |
| 267 | if (_addSubscriptions.find(name) == _addSubscriptions.end()) |
| 268 | { |
| 269 | _addSubscriptions.emplace(name, func); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * @brief Unsubscribe from new PELs. |
| 275 | * |
| 276 | * @param[in] name - The subscription name |
| 277 | */ |
| 278 | void unsubscribeFromAdds(const std::string& name) |
| 279 | { |
| 280 | _addSubscriptions.erase(name); |
| 281 | } |
| 282 | |
| 283 | using DeleteCallback = std::function<void(uint32_t)>; |
| 284 | |
| 285 | /** |
| 286 | * @brief Subscribe to PELs being deleted from the repository. |
| 287 | * |
| 288 | * Every time a PEL is deleted from the repository, the provided |
| 289 | * function will be called with the PEL ID as the argument. |
| 290 | * |
| 291 | * The function must be of type void(const uint32_t). |
| 292 | * |
| 293 | * @param[in] name - The subscription name |
| 294 | * @param[in] func - The callback function |
| 295 | */ |
| 296 | void subscribeToDeletes(const std::string& name, DeleteCallback func) |
| 297 | { |
| 298 | if (_deleteSubscriptions.find(name) == _deleteSubscriptions.end()) |
| 299 | { |
| 300 | _deleteSubscriptions.emplace(name, func); |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * @brief Unsubscribe from deleted PELs. |
| 306 | * |
| 307 | * @param[in] name - The subscription name |
| 308 | */ |
| 309 | void unsubscribeFromDeletes(const std::string& name) |
| 310 | { |
| 311 | _deleteSubscriptions.erase(name); |
| 312 | } |
| 313 | |
Matt Spinler | 0ff0048 | 2019-11-06 16:19:46 -0600 | [diff] [blame] | 314 | /** |
| 315 | * @brief Get the PEL attributes for a PEL |
| 316 | * |
| 317 | * @param[in] id - The ID to find the attributes for |
| 318 | * |
| 319 | * @return The attributes or an empty optional if not found |
| 320 | */ |
| 321 | std::optional<std::reference_wrapper<const PELAttributes>> |
| 322 | getPELAttributes(const LogID& id) const; |
| 323 | |
Matt Spinler | 29d18c1 | 2019-11-21 13:31:27 -0600 | [diff] [blame] | 324 | /** |
| 325 | * @brief Sets the host transmission state on a PEL file |
| 326 | * |
| 327 | * Writes the host transmission state field in the User Header |
| 328 | * section in the PEL data specified by the ID. |
| 329 | * |
| 330 | * @param[in] pelID - The PEL ID |
| 331 | * @param[in] state - The state to write |
| 332 | */ |
| 333 | void setPELHostTransState(uint32_t pelID, TransmissionState state); |
| 334 | |
| 335 | /** |
| 336 | * @brief Sets the HMC transmission state on a PEL file |
| 337 | * |
| 338 | * Writes the HMC transmission state field in the User Header |
| 339 | * section in the PEL data specified by the ID. |
| 340 | * |
| 341 | * @param[in] pelID - The PEL ID |
| 342 | * @param[in] state - The state to write |
| 343 | */ |
| 344 | void setPELHMCTransState(uint32_t pelID, TransmissionState state); |
| 345 | |
Matt Spinler | b188f78 | 2020-07-07 11:18:12 -0500 | [diff] [blame] | 346 | /** |
| 347 | * @brief Returns the size stats structure |
| 348 | * |
| 349 | * @return const SizeStats& - The stats structure |
| 350 | */ |
| 351 | const SizeStats& getSizeStats() const |
| 352 | { |
| 353 | return _sizes; |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * @brief Says if the PEL is considered serviceable (not just |
| 358 | * informational) as determined by its severity. |
| 359 | * |
| 360 | * @param[in] pel - The PELAttributes entry for the PEL |
| 361 | * @return bool - If serviceable or not |
| 362 | */ |
| 363 | static bool isServiceableSev(const PELAttributes& pel); |
| 364 | |
Matt Spinler | b0a8df5 | 2020-07-07 14:41:06 -0500 | [diff] [blame] | 365 | /** |
Matt Spinler | 7e727a3 | 2020-07-07 15:00:17 -0500 | [diff] [blame] | 366 | * @brief Returns true if the total amount of disk space occupied |
| 367 | * by the PELs in the repo is over 95% of the maximum |
| 368 | * size, or if there are over the maximum number of |
| 369 | * PELs allowed. |
| 370 | * |
| 371 | * @return bool - true if repo is > 95% full or too many PELs |
| 372 | */ |
| 373 | bool sizeWarning() const; |
| 374 | |
| 375 | /** |
Matt Spinler | b0a8df5 | 2020-07-07 14:41:06 -0500 | [diff] [blame] | 376 | * @brief Deletes PELs to bring the repository size down |
| 377 | * to at most 90% full by placing PELs into 4 different |
| 378 | * catogories and then removing PELs until those catogories |
| 379 | * only take up certain percentages of the allowed space. |
| 380 | * |
| 381 | * This does not delete the corresponding OpenBMC event logs, which |
| 382 | * is why those IDs are returned, so they can be deleted later. |
| 383 | * |
| 384 | * The categories and their rules are: |
| 385 | * 1) Informational BMC PELs cannot take up more than 15% of |
| 386 | * the allocated space. |
| 387 | * 2) Non-informational BMC PELs cannot take up more than 30% |
| 388 | * of the allocated space. |
| 389 | * 3) Informational non-BMC PELs cannot take up more than 15% of |
| 390 | * the allocated space. |
| 391 | * 4) Non-informational non-BMC PELs cannot take up more than 30% |
| 392 | * of the allocated space. |
| 393 | * |
| 394 | * While removing PELs in a category, 4 passes will be made, with |
| 395 | * PELs being removed oldest first during each pass. |
| 396 | * |
| 397 | * Pass 1: only delete HMC acked PELs |
| 398 | * Pass 2: only delete OS acked PELs |
| 399 | * Pass 3: only delete PHYP sent PELs |
| 400 | * Pass 4: delete all PELs |
| 401 | * |
| 402 | * @return std::vector<uint32_t> - The OpenBMC event log IDs of |
| 403 | * the PELs that were deleted. |
| 404 | */ |
| 405 | std::vector<uint32_t> prune(); |
| 406 | |
Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 407 | /** |
| 408 | * @brief Returns the path to the directory where the PEL |
| 409 | * files are stored. |
| 410 | * |
| 411 | * @return std::filesystem::path - The directory path |
| 412 | */ |
| 413 | const std::filesystem::path& repoPath() const |
| 414 | { |
| 415 | return _logPath; |
| 416 | } |
| 417 | |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 418 | private: |
Matt Spinler | 29d18c1 | 2019-11-21 13:31:27 -0600 | [diff] [blame] | 419 | using PELUpdateFunc = std::function<void(PEL&)>; |
| 420 | |
| 421 | /** |
| 422 | * @brief Lets a function modify a PEL and saves the results |
| 423 | * |
| 424 | * Runs updateFunc (a void(PEL&) function) on the PEL data |
| 425 | * on the file specified, and writes the results back to the file. |
| 426 | * |
| 427 | * @param[in] path - The file path to use |
| 428 | * @param[in] updateFunc - The function to run to update the PEL. |
| 429 | */ |
| 430 | void updatePEL(const std::filesystem::path& path, PELUpdateFunc updateFunc); |
| 431 | |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 432 | /** |
Matt Spinler | 0ff0048 | 2019-11-06 16:19:46 -0600 | [diff] [blame] | 433 | * @brief Finds an entry in the _pelAttributes map. |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 434 | * |
| 435 | * @param[in] id - the ID (either the pel ID, OBMC ID, or both) |
| 436 | * |
| 437 | * @return an iterator to the entry |
| 438 | */ |
Matt Spinler | 0ff0048 | 2019-11-06 16:19:46 -0600 | [diff] [blame] | 439 | std::map<LogID, PELAttributes>::const_iterator |
| 440 | findPEL(const LogID& id) const |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 441 | { |
Matt Spinler | 0ff0048 | 2019-11-06 16:19:46 -0600 | [diff] [blame] | 442 | return std::find_if(_pelAttributes.begin(), _pelAttributes.end(), |
| 443 | [&id](const auto& a) { return a.first == id; }); |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /** |
Matt Spinler | 421f653 | 2019-11-06 15:40:45 -0600 | [diff] [blame] | 447 | * @brief Call any subscribed functions for new PELs |
| 448 | * |
| 449 | * @param[in] pel - The new PEL |
| 450 | */ |
| 451 | void processAddCallbacks(const PEL& pel) const; |
| 452 | |
| 453 | /** |
| 454 | * @brief Call any subscribed functions for deleted PELs |
| 455 | * |
| 456 | * @param[in] id - The ID of the deleted PEL |
| 457 | */ |
| 458 | void processDeleteCallbacks(uint32_t id) const; |
| 459 | |
| 460 | /** |
Matt Spinler | 0ff0048 | 2019-11-06 16:19:46 -0600 | [diff] [blame] | 461 | * @brief Restores the _pelAttributes map on startup based on the existing |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 462 | * PEL data files. |
| 463 | */ |
| 464 | void restore(); |
| 465 | |
| 466 | /** |
Matt Spinler | ab1b97f | 2019-11-07 13:38:07 -0600 | [diff] [blame] | 467 | * @brief Stores a PEL object in the filesystem. |
| 468 | * |
| 469 | * @param[in] pel - The PEL to write |
| 470 | * @param[in] path - The file to write to |
| 471 | * |
| 472 | * Throws exceptions on failures. |
| 473 | */ |
| 474 | void write(const PEL& pel, const std::filesystem::path& path); |
| 475 | |
| 476 | /** |
Matt Spinler | b188f78 | 2020-07-07 11:18:12 -0500 | [diff] [blame] | 477 | * @brief Updates the repository statistics after a PEL is |
| 478 | * added or removed. |
| 479 | * |
| 480 | * @param[in] pel - The PELAttributes entry for the PEL |
| 481 | * @param[in] pelAdded - true if the PEL was added, false if removed |
| 482 | */ |
| 483 | void updateRepoStats(const PELAttributes& pel, bool pelAdded); |
| 484 | |
Matt Spinler | b0a8df5 | 2020-07-07 14:41:06 -0500 | [diff] [blame] | 485 | enum class SortOrder |
| 486 | { |
| 487 | ascending, |
| 488 | descending |
| 489 | }; |
| 490 | |
| 491 | /** |
| 492 | * @brief Returns a vector of all the _pelAttributes entries sorted |
| 493 | * as specified |
| 494 | * |
| 495 | * @param[in] order - If the PELs should be returned in ascending |
| 496 | * (oldest first) or descending order. |
| 497 | * |
| 498 | * @return std::vector<AttributesReference> - The sorted vector of |
| 499 | * references to the pair<LogID, PELAttributes> entries of |
| 500 | * _pelAttributes. |
| 501 | */ |
| 502 | std::vector<AttributesReference> getAllPELAttributes(SortOrder order) const; |
| 503 | |
| 504 | using IsOverLimitFunc = std::function<bool()>; |
| 505 | using IsPELTypeFunc = std::function<bool(const PELAttributes&)>; |
| 506 | |
| 507 | /** |
| 508 | * @brief Makes 4 passes on the PELs that meet the IsPELTypeFunc |
| 509 | * criteria removing PELs until IsOverLimitFunc returns false. |
| 510 | * |
| 511 | * Pass 1: only delete HMC acked PELs |
| 512 | * Pass 2: only delete Os acked PELs |
| 513 | * Pass 3: only delete PHYP sent PELs |
| 514 | * Pass 4: delete all PELs |
| 515 | * |
| 516 | * @param[in] isOverLimit - The bool(void) function that should |
| 517 | * return true if PELs still need to be |
| 518 | * removed. |
| 519 | * @param[in] isPELType - The bool(const PELAttributes&) function |
| 520 | * used to select the PELs to operate on. |
| 521 | * |
| 522 | * @param[out] removedBMCLogIDs - The OpenBMC event log IDs of the |
| 523 | * removed PELs. |
| 524 | */ |
| 525 | void removePELs(IsOverLimitFunc& isOverLimit, IsPELTypeFunc& isPELType, |
| 526 | std::vector<uint32_t>& removedBMCLogIDs); |
Matt Spinler | b188f78 | 2020-07-07 11:18:12 -0500 | [diff] [blame] | 527 | /** |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 528 | * @brief The filesystem path to the PEL logs. |
| 529 | */ |
| 530 | const std::filesystem::path _logPath; |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 531 | |
| 532 | /** |
Matt Spinler | 0ff0048 | 2019-11-06 16:19:46 -0600 | [diff] [blame] | 533 | * @brief A map of the PEL/OBMC IDs to PEL attributes. |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 534 | */ |
Matt Spinler | 0ff0048 | 2019-11-06 16:19:46 -0600 | [diff] [blame] | 535 | std::map<LogID, PELAttributes> _pelAttributes; |
Matt Spinler | 421f653 | 2019-11-06 15:40:45 -0600 | [diff] [blame] | 536 | |
| 537 | /** |
| 538 | * @brief Subcriptions for new PELs. |
| 539 | */ |
| 540 | std::map<std::string, AddCallback> _addSubscriptions; |
| 541 | |
| 542 | /** |
| 543 | * @brief Subscriptions for deleted PELs. |
| 544 | */ |
| 545 | std::map<std::string, DeleteCallback> _deleteSubscriptions; |
Matt Spinler | 8d5f3a2 | 2020-07-07 10:30:33 -0500 | [diff] [blame] | 546 | |
| 547 | /** |
| 548 | * @brief The maximum amount of space that the PELs in the |
| 549 | * repository can occupy. |
| 550 | */ |
| 551 | const uint64_t _maxRepoSize; |
| 552 | |
| 553 | /** |
| 554 | * @brief The maximum number of PELs to allow in the repo |
| 555 | * before pruning. |
| 556 | */ |
| 557 | const size_t _maxNumPELs; |
Matt Spinler | b188f78 | 2020-07-07 11:18:12 -0500 | [diff] [blame] | 558 | |
| 559 | /** |
| 560 | * @brief Statistics on the sizes of the stored PELs. |
| 561 | */ |
| 562 | SizeStats _sizes; |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 563 | }; |
| 564 | |
| 565 | } // namespace pels |
| 566 | } // namespace openpower |