blob: 59b3eaa7b148c9ec7c39c51995cfc7ebb480872d [file] [log] [blame]
Matt Spinler711d51d2019-11-06 09:36:51 -06001/**
2 * Copyright © 2019 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Matt Spinler89fa0822019-07-17 13:54:30 -050016#include "repository.hpp"
17
Matt Spinlerdd325c32020-07-07 11:01:54 -050018#include <sys/stat.h>
19
Matt Spinler89fa0822019-07-17 13:54:30 -050020#include <fstream>
21#include <phosphor-logging/log.hpp>
22#include <xyz/openbmc_project/Common/File/error.hpp>
23
24namespace openpower
25{
26namespace pels
27{
28
29namespace fs = std::filesystem;
30using namespace phosphor::logging;
31namespace file_error = sdbusplus::xyz::openbmc_project::Common::File::Error;
32
Matt Spinler7e727a32020-07-07 15:00:17 -050033constexpr size_t warningPercentage = 95;
34
Matt Spinlerdd325c32020-07-07 11:01:54 -050035/**
36 * @brief Returns the amount of space the file uses on disk.
37 *
38 * This is different than just the regular size of the file.
39 *
40 * @param[in] file - The file to get the size of
41 *
42 * @return size_t The disk space the file uses
43 */
44size_t getFileDiskSize(const std::filesystem::path& file)
45{
46 constexpr size_t statBlockSize = 512;
47 struct stat statData;
48 auto rc = stat(file.c_str(), &statData);
49 if (rc != 0)
50 {
51 auto e = errno;
52 std::string msg = "call to stat() failed on " + file.native() +
53 " with errno " + std::to_string(e);
54 log<level::ERR>(msg.c_str());
55 abort();
56 }
57
58 return statData.st_blocks * statBlockSize;
59}
60
Matt Spinler8d5f3a22020-07-07 10:30:33 -050061Repository::Repository(const std::filesystem::path& basePath, size_t repoSize,
62 size_t maxNumPELs) :
63 _logPath(basePath / "logs"),
64 _maxRepoSize(repoSize), _maxNumPELs(maxNumPELs)
Matt Spinler89fa0822019-07-17 13:54:30 -050065{
66 if (!fs::exists(_logPath))
67 {
68 fs::create_directories(_logPath);
69 }
Matt Spinler475e5742019-07-18 16:09:49 -050070
71 restore();
72}
73
74void Repository::restore()
75{
76 for (auto& dirEntry : fs::directory_iterator(_logPath))
77 {
78 try
79 {
80 if (!fs::is_regular_file(dirEntry.path()))
81 {
82 continue;
83 }
84
85 std::ifstream file{dirEntry.path()};
86 std::vector<uint8_t> data{std::istreambuf_iterator<char>(file),
87 std::istreambuf_iterator<char>()};
88 file.close();
89
Matt Spinler07eefc52019-09-26 11:18:26 -050090 PEL pel{data};
Matt Spinler475e5742019-07-18 16:09:49 -050091 if (pel.valid())
92 {
Matt Spinlera3c12a42019-11-21 13:25:32 -060093 // If the host hasn't acked it, reset the host state so
94 // it will get sent up again.
95 if (pel.hostTransmissionState() == TransmissionState::sent)
96 {
97 pel.setHostTransmissionState(TransmissionState::newPEL);
98 try
99 {
100 write(pel, dirEntry.path());
101 }
102 catch (std::exception& e)
103 {
104 log<level::ERR>(
105 "Failed to save PEL after updating host state",
106 entry("PELID=0x%X", pel.id()));
107 }
108 }
109
Matt Spinlerdd325c32020-07-07 11:01:54 -0500110 PELAttributes attributes{dirEntry.path(),
111 getFileDiskSize(dirEntry.path()),
112 pel.privateHeader().creatorID(),
113 pel.userHeader().severity(),
114 pel.userHeader().actionFlags(),
115 pel.hostTransmissionState(),
116 pel.hmcTransmissionState()};
Matt Spinler0ff00482019-11-06 16:19:46 -0600117
Matt Spinler475e5742019-07-18 16:09:49 -0500118 using pelID = LogID::Pel;
119 using obmcID = LogID::Obmc;
Matt Spinler0ff00482019-11-06 16:19:46 -0600120 _pelAttributes.emplace(
Matt Spinler475e5742019-07-18 16:09:49 -0500121 LogID(pelID(pel.id()), obmcID(pel.obmcLogID())),
Matt Spinler0ff00482019-11-06 16:19:46 -0600122 attributes);
Matt Spinlerb188f782020-07-07 11:18:12 -0500123
124 updateRepoStats(attributes, true);
Matt Spinler475e5742019-07-18 16:09:49 -0500125 }
126 else
127 {
128 log<level::ERR>(
129 "Found invalid PEL file while restoring. Removing.",
130 entry("FILENAME=%s", dirEntry.path().c_str()));
131 fs::remove(dirEntry.path());
132 }
133 }
134 catch (std::exception& e)
135 {
136 log<level::ERR>("Hit exception while restoring PEL File",
137 entry("FILENAME=%s", dirEntry.path().c_str()),
138 entry("ERROR=%s", e.what()));
139 }
140 }
Matt Spinler89fa0822019-07-17 13:54:30 -0500141}
142
143std::string Repository::getPELFilename(uint32_t pelID, const BCDTime& time)
144{
145 char name[50];
146 sprintf(name, "%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X_%.8X", time.yearMSB,
147 time.yearLSB, time.month, time.day, time.hour, time.minutes,
148 time.seconds, time.hundredths, pelID);
149 return std::string{name};
150}
151
152void Repository::add(std::unique_ptr<PEL>& pel)
153{
Matt Spinlerdf43a302019-11-21 13:16:56 -0600154 pel->setHostTransmissionState(TransmissionState::newPEL);
155 pel->setHMCTransmissionState(TransmissionState::newPEL);
156
Matt Spinler89fa0822019-07-17 13:54:30 -0500157 auto path = _logPath / getPELFilename(pel->id(), pel->commitTime());
Matt Spinlerab1b97f2019-11-07 13:38:07 -0600158
159 write(*(pel.get()), path);
160
Matt Spinlerdd325c32020-07-07 11:01:54 -0500161 PELAttributes attributes{path,
162 getFileDiskSize(path),
163 pel->privateHeader().creatorID(),
164 pel->userHeader().severity(),
165 pel->userHeader().actionFlags(),
Matt Spinler346f99a2019-11-21 13:06:35 -0600166 pel->hostTransmissionState(),
167 pel->hmcTransmissionState()};
Matt Spinlerab1b97f2019-11-07 13:38:07 -0600168
169 using pelID = LogID::Pel;
170 using obmcID = LogID::Obmc;
171 _pelAttributes.emplace(LogID(pelID(pel->id()), obmcID(pel->obmcLogID())),
172 attributes);
173
Matt Spinlerb188f782020-07-07 11:18:12 -0500174 updateRepoStats(attributes, true);
175
Matt Spinlerab1b97f2019-11-07 13:38:07 -0600176 processAddCallbacks(*pel);
177}
178
179void Repository::write(const PEL& pel, const fs::path& path)
180{
Matt Spinler89fa0822019-07-17 13:54:30 -0500181 std::ofstream file{path, std::ios::binary};
182
183 if (!file.good())
184 {
185 // If this fails, the filesystem is probably full so it isn't like
186 // we could successfully create yet another error log here.
187 auto e = errno;
Matt Spinler89fa0822019-07-17 13:54:30 -0500188 fs::remove(path);
189 log<level::ERR>("Unable to open PEL file for writing",
190 entry("ERRNO=%d", e), entry("PATH=%s", path.c_str()));
191 throw file_error::Open();
192 }
193
Matt Spinlerab1b97f2019-11-07 13:38:07 -0600194 auto data = pel.data();
Matt Spinler89fa0822019-07-17 13:54:30 -0500195 file.write(reinterpret_cast<const char*>(data.data()), data.size());
196
197 if (file.fail())
198 {
199 // Same note as above about not being able to create an error log
200 // for this case even if we wanted.
201 auto e = errno;
Matt Spinler89fa0822019-07-17 13:54:30 -0500202 file.close();
203 fs::remove(path);
204 log<level::ERR>("Unable to write PEL file", entry("ERRNO=%d", e),
205 entry("PATH=%s", path.c_str()));
206 throw file_error::Write();
207 }
Matt Spinler475e5742019-07-18 16:09:49 -0500208}
209
210void Repository::remove(const LogID& id)
211{
212 auto pel = findPEL(id);
Matt Spinler0ff00482019-11-06 16:19:46 -0600213 if (pel != _pelAttributes.end())
Matt Spinler475e5742019-07-18 16:09:49 -0500214 {
Matt Spinlerb188f782020-07-07 11:18:12 -0500215 updateRepoStats(pel->second, false);
216
Matt Spinler5f5352e2020-03-05 16:23:27 -0600217 log<level::DEBUG>("Removing PEL from repository",
218 entry("PEL_ID=0x%X", pel->first.pelID.id),
219 entry("OBMC_LOG_ID=%d", pel->first.obmcID.id));
Matt Spinler0ff00482019-11-06 16:19:46 -0600220 fs::remove(pel->second.path);
221 _pelAttributes.erase(pel);
Matt Spinler421f6532019-11-06 15:40:45 -0600222
Matt Spinler5f5352e2020-03-05 16:23:27 -0600223 processDeleteCallbacks(pel->first.pelID.id);
224 }
225 else
226 {
227 log<level::DEBUG>("Could not find PEL to remove",
228 entry("PEL_ID=0x%X", id.pelID.id),
229 entry("OBMC_LOG_ID=%d", id.obmcID.id));
Matt Spinler475e5742019-07-18 16:09:49 -0500230 }
Matt Spinler89fa0822019-07-17 13:54:30 -0500231}
232
Matt Spinler2813f362019-07-19 12:45:28 -0500233std::optional<std::vector<uint8_t>> Repository::getPELData(const LogID& id)
234{
235 auto pel = findPEL(id);
Matt Spinler0ff00482019-11-06 16:19:46 -0600236 if (pel != _pelAttributes.end())
Matt Spinler2813f362019-07-19 12:45:28 -0500237 {
Matt Spinler0ff00482019-11-06 16:19:46 -0600238 std::ifstream file{pel->second.path.c_str()};
Matt Spinler2813f362019-07-19 12:45:28 -0500239 if (!file.good())
240 {
241 auto e = errno;
242 log<level::ERR>("Unable to open PEL file", entry("ERRNO=%d", e),
Matt Spinler0ff00482019-11-06 16:19:46 -0600243 entry("PATH=%s", pel->second.path.c_str()));
Matt Spinler2813f362019-07-19 12:45:28 -0500244 throw file_error::Open();
245 }
246
247 std::vector<uint8_t> data{std::istreambuf_iterator<char>(file),
248 std::istreambuf_iterator<char>()};
249 return data;
250 }
251
252 return std::nullopt;
253}
254
Matt Spinler6d512242019-12-09 13:44:17 -0600255std::optional<sdbusplus::message::unix_fd> Repository::getPELFD(const LogID& id)
256{
257 auto pel = findPEL(id);
258 if (pel != _pelAttributes.end())
259 {
260 FILE* fp = fopen(pel->second.path.c_str(), "rb");
261
262 if (fp == nullptr)
263 {
264 auto e = errno;
265 log<level::ERR>("Unable to open PEL File", entry("ERRNO=%d", e),
266 entry("PATH=%s", pel->second.path.c_str()));
267 throw file_error::Open();
268 }
269
270 // Must leave the file open here. It will be closed by sdbusplus
271 // when it sends it back over D-Bus.
272
273 return fileno(fp);
274 }
275 return std::nullopt;
276}
277
Matt Spinler1ea78802019-11-01 13:04:59 -0500278void Repository::for_each(ForEachFunc func) const
279{
Matt Spinler0ff00482019-11-06 16:19:46 -0600280 for (const auto& [id, attributes] : _pelAttributes)
Matt Spinler1ea78802019-11-01 13:04:59 -0500281 {
Matt Spinler0ff00482019-11-06 16:19:46 -0600282 std::ifstream file{attributes.path};
Matt Spinler1ea78802019-11-01 13:04:59 -0500283
284 if (!file.good())
285 {
286 auto e = errno;
287 log<level::ERR>("Repository::for_each: Unable to open PEL file",
288 entry("ERRNO=%d", e),
Matt Spinler0ff00482019-11-06 16:19:46 -0600289 entry("PATH=%s", attributes.path.c_str()));
Matt Spinler1ea78802019-11-01 13:04:59 -0500290 continue;
291 }
292
293 std::vector<uint8_t> data{std::istreambuf_iterator<char>(file),
294 std::istreambuf_iterator<char>()};
295 file.close();
296
297 PEL pel{data};
298
299 try
300 {
301 if (func(pel))
302 {
303 break;
304 }
305 }
306 catch (std::exception& e)
307 {
308 log<level::ERR>("Repository::for_each function exception",
309 entry("ERROR=%s", e.what()));
310 }
311 }
312}
313
Matt Spinler421f6532019-11-06 15:40:45 -0600314void Repository::processAddCallbacks(const PEL& pel) const
315{
316 for (auto& [name, func] : _addSubscriptions)
317 {
318 try
319 {
320 func(pel);
321 }
322 catch (std::exception& e)
323 {
324 log<level::ERR>("PEL Repository add callback exception",
325 entry("NAME=%s", name.c_str()),
326 entry("ERROR=%s", e.what()));
327 }
328 }
329}
330
331void Repository::processDeleteCallbacks(uint32_t id) const
332{
333 for (auto& [name, func] : _deleteSubscriptions)
334 {
335 try
336 {
337 func(id);
338 }
339 catch (std::exception& e)
340 {
341 log<level::ERR>("PEL Repository delete callback exception",
342 entry("NAME=%s", name.c_str()),
343 entry("ERROR=%s", e.what()));
344 }
345 }
346}
347
Matt Spinler0ff00482019-11-06 16:19:46 -0600348std::optional<std::reference_wrapper<const Repository::PELAttributes>>
349 Repository::getPELAttributes(const LogID& id) const
350{
351 auto pel = findPEL(id);
352 if (pel != _pelAttributes.end())
353 {
354 return pel->second;
355 }
356
357 return std::nullopt;
358}
359
Matt Spinler29d18c12019-11-21 13:31:27 -0600360void Repository::setPELHostTransState(uint32_t pelID, TransmissionState state)
361{
362 LogID id{LogID::Pel{pelID}};
363 auto attr = std::find_if(_pelAttributes.begin(), _pelAttributes.end(),
364 [&id](const auto& a) { return a.first == id; });
365
366 if ((attr != _pelAttributes.end()) && (attr->second.hostState != state))
367 {
368 PELUpdateFunc func = [state](PEL& pel) {
369 pel.setHostTransmissionState(state);
370 };
371
372 try
373 {
374 updatePEL(attr->second.path, func);
375
376 attr->second.hostState = state;
377 }
378 catch (std::exception& e)
379 {
380 log<level::ERR>("Unable to update PEL host transmission state",
381 entry("PATH=%s", attr->second.path.c_str()),
382 entry("ERROR=%s", e.what()));
383 }
384 }
385}
386
387void Repository::setPELHMCTransState(uint32_t pelID, TransmissionState state)
388{
389 LogID id{LogID::Pel{pelID}};
390 auto attr = std::find_if(_pelAttributes.begin(), _pelAttributes.end(),
391 [&id](const auto& a) { return a.first == id; });
392
393 if ((attr != _pelAttributes.end()) && (attr->second.hmcState != state))
394 {
395 PELUpdateFunc func = [state](PEL& pel) {
396 pel.setHMCTransmissionState(state);
397 };
398
399 try
400 {
401 updatePEL(attr->second.path, func);
402
403 attr->second.hmcState = state;
404 }
405 catch (std::exception& e)
406 {
407 log<level::ERR>("Unable to update PEL HMC transmission state",
408 entry("PATH=%s", attr->second.path.c_str()),
409 entry("ERROR=%s", e.what()));
410 }
411 }
412}
413
414void Repository::updatePEL(const fs::path& path, PELUpdateFunc updateFunc)
415{
416 std::ifstream file{path};
417 std::vector<uint8_t> data{std::istreambuf_iterator<char>(file),
418 std::istreambuf_iterator<char>()};
419 file.close();
420
421 PEL pel{data};
422
423 if (pel.valid())
424 {
425 updateFunc(pel);
426
427 write(pel, path);
428 }
429 else
430 {
431 throw std::runtime_error(
432 "Unable to read a valid PEL when trying to update it");
433 }
434}
435
Matt Spinlerb188f782020-07-07 11:18:12 -0500436bool Repository::isServiceableSev(const PELAttributes& pel)
437{
438 auto sevType = static_cast<SeverityType>(pel.severity & 0xF0);
439 auto sevPVEntry =
440 pel_values::findByValue(pel.severity, pel_values::severityValues);
441 std::string sevName = std::get<pel_values::registryNamePos>(*sevPVEntry);
442
443 bool check1 = (sevType == SeverityType::predictive) ||
444 (sevType == SeverityType::unrecoverable) ||
445 (sevType == SeverityType::critical);
446
447 bool check2 = ((sevType == SeverityType::recovered) ||
448 (sevName == "symptom_recovered")) &&
449 !pel.actionFlags.test(hiddenFlagBit);
450
451 bool check3 = (sevName == "symptom_predictive") ||
452 (sevName == "symptom_unrecoverable") ||
453 (sevName == "symptom_critical");
454
455 return check1 || check2 || check3;
456}
457
458void Repository::updateRepoStats(const PELAttributes& pel, bool pelAdded)
459{
460 auto isServiceable = Repository::isServiceableSev(pel);
461 auto bmcPEL = CreatorID::openBMC == static_cast<CreatorID>(pel.creator);
462
463 auto adjustSize = [pelAdded, &pel](auto& runningSize) {
464 if (pelAdded)
465 {
466 runningSize += pel.sizeOnDisk;
467 }
468 else
469 {
470 runningSize = std::max(static_cast<int64_t>(runningSize) -
471 static_cast<int64_t>(pel.sizeOnDisk),
472 static_cast<int64_t>(0));
473 }
474 };
475
476 adjustSize(_sizes.total);
477
478 if (bmcPEL)
479 {
480 adjustSize(_sizes.bmc);
481 if (isServiceable)
482 {
483 adjustSize(_sizes.bmcServiceable);
484 }
485 else
486 {
487 adjustSize(_sizes.bmcInfo);
488 }
489 }
490 else
491 {
492 adjustSize(_sizes.nonBMC);
493 if (isServiceable)
494 {
495 adjustSize(_sizes.nonBMCServiceable);
496 }
497 else
498 {
499 adjustSize(_sizes.nonBMCInfo);
500 }
501 }
502}
503
Matt Spinler7e727a32020-07-07 15:00:17 -0500504bool Repository::sizeWarning() const
505{
506 return (_sizes.total > (_maxRepoSize * warningPercentage / 100)) ||
507 (_pelAttributes.size() > _maxNumPELs);
508}
509
Matt Spinlerb0a8df52020-07-07 14:41:06 -0500510std::vector<Repository::AttributesReference>
511 Repository::getAllPELAttributes(SortOrder order) const
512{
513 std::vector<Repository::AttributesReference> attributes;
514
515 std::for_each(
516 _pelAttributes.begin(), _pelAttributes.end(),
517 [&attributes](auto& pelEntry) { attributes.push_back(pelEntry); });
518
519 std::sort(attributes.begin(), attributes.end(),
520 [order](const auto& left, const auto& right) {
521 if (order == SortOrder::ascending)
522 {
523 return left.get().second.path < right.get().second.path;
524 }
525 return left.get().second.path > right.get().second.path;
526 });
527
528 return attributes;
529}
530
531std::vector<uint32_t> Repository::prune()
532{
533 std::vector<uint32_t> obmcLogIDs;
534 std::string msg = "Pruning PEL repository that takes up " +
535 std::to_string(_sizes.total) + " bytes and has " +
536 std::to_string(_pelAttributes.size()) + " PELs";
537 log<level::INFO>(msg.c_str());
538
539 // Set up the 5 functions to check if the PEL category
540 // is still over its limits.
541
542 // BMC informational PELs should only take up 15%
543 IsOverLimitFunc overBMCInfoLimit = [this]() {
544 return _sizes.bmcInfo > _maxRepoSize * 15 / 100;
545 };
546
547 // BMC non informational PELs should only take up 30%
548 IsOverLimitFunc overBMCNonInfoLimit = [this]() {
549 return _sizes.bmcServiceable > _maxRepoSize * 30 / 100;
550 };
551
552 // Non BMC informational PELs should only take up 15%
553 IsOverLimitFunc overNonBMCInfoLimit = [this]() {
554 return _sizes.nonBMCInfo > _maxRepoSize * 15 / 100;
555 };
556
557 // Non BMC non informational PELs should only take up 15%
558 IsOverLimitFunc overNonBMCNonInfoLimit = [this]() {
559 return _sizes.nonBMCServiceable > _maxRepoSize * 30 / 100;
560 };
561
562 // Bring the total number of PELs down to 80% of the max
563 IsOverLimitFunc tooManyPELsLimit = [this]() {
564 return _pelAttributes.size() > _maxNumPELs * 80 / 100;
565 };
566
567 // Set up the functions to determine which category a PEL is in.
568 // TODO: Return false in these functions if a PEL caused a guard record.
569
570 // A BMC informational PEL
571 IsPELTypeFunc isBMCInfo = [](const PELAttributes& pel) {
572 return (CreatorID::openBMC == static_cast<CreatorID>(pel.creator)) &&
573 !Repository::isServiceableSev(pel);
574 };
575
576 // A BMC non informational PEL
577 IsPELTypeFunc isBMCNonInfo = [](const PELAttributes& pel) {
578 return (CreatorID::openBMC == static_cast<CreatorID>(pel.creator)) &&
579 Repository::isServiceableSev(pel);
580 };
581
582 // A non BMC informational PEL
583 IsPELTypeFunc isNonBMCInfo = [](const PELAttributes& pel) {
584 return (CreatorID::openBMC != static_cast<CreatorID>(pel.creator)) &&
585 !Repository::isServiceableSev(pel);
586 };
587
588 // A non BMC non informational PEL
589 IsPELTypeFunc isNonBMCNonInfo = [](const PELAttributes& pel) {
590 return (CreatorID::openBMC != static_cast<CreatorID>(pel.creator)) &&
591 Repository::isServiceableSev(pel);
592 };
593
594 // When counting PELs, count every PEL
595 IsPELTypeFunc isAnyPEL = [](const PELAttributes& pel) { return true; };
596
597 // Check all 4 categories, which will result in at most 90%
598 // usage (15 + 30 + 15 + 30).
599 removePELs(overBMCInfoLimit, isBMCInfo, obmcLogIDs);
600 removePELs(overBMCNonInfoLimit, isBMCNonInfo, obmcLogIDs);
601 removePELs(overNonBMCInfoLimit, isNonBMCInfo, obmcLogIDs);
602 removePELs(overNonBMCNonInfoLimit, isNonBMCNonInfo, obmcLogIDs);
603
604 // After the above pruning check if there are still too many PELs,
605 // which can happen depending on PEL sizes.
606 if (_pelAttributes.size() > _maxNumPELs)
607 {
608 removePELs(tooManyPELsLimit, isAnyPEL, obmcLogIDs);
609 }
610
611 if (!obmcLogIDs.empty())
612 {
613 std::string msg = "Number of PELs removed to save space: " +
614 std::to_string(obmcLogIDs.size());
615 log<level::INFO>(msg.c_str());
616 }
617
618 return obmcLogIDs;
619}
620
621void Repository::removePELs(IsOverLimitFunc& isOverLimit,
622 IsPELTypeFunc& isPELType,
623 std::vector<uint32_t>& removedBMCLogIDs)
624{
625 if (!isOverLimit())
626 {
627 return;
628 }
629
630 auto attributes = getAllPELAttributes(SortOrder::ascending);
631
632 // Make 4 passes on the PELs, stopping as soon as isOverLimit
633 // returns false.
634 // Pass 1: only delete HMC acked PELs
635 // Pass 2: only delete OS acked PELs
636 // Pass 3: only delete PHYP sent PELs
637 // Pass 4: delete all PELs
638 static const std::vector<std::function<bool(const PELAttributes& pel)>>
639 stateChecks{[](const auto& pel) {
640 return pel.hmcState == TransmissionState::acked;
641 },
642
643 [](const auto& pel) {
644 return pel.hostState == TransmissionState::acked;
645 },
646
647 [](const auto& pel) {
648 return pel.hostState == TransmissionState::sent;
649 },
650
651 [](const auto& pel) { return true; }};
652
653 for (const auto& stateCheck : stateChecks)
654 {
655 for (auto it = attributes.begin(); it != attributes.end();)
656 {
657 const auto& pel = it->get();
658 if (isPELType(pel.second) && stateCheck(pel.second))
659 {
660 auto removedID = pel.first.obmcID.id;
661 remove(pel.first);
662
663 removedBMCLogIDs.push_back(removedID);
664
665 attributes.erase(it);
666
667 if (!isOverLimit())
668 {
669 break;
670 }
671 }
672 else
673 {
674 ++it;
675 }
676 }
677
678 if (!isOverLimit())
679 {
680 break;
681 }
682 }
683}
684
Matt Spinler89fa0822019-07-17 13:54:30 -0500685} // namespace pels
686} // namespace openpower