blob: e9e5a18456e5fdcd6a1c75520c66c5e72e82408e [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
Matt Spinler52602e32020-07-15 12:37:28 -0500210std::optional<Repository::LogID> Repository::remove(const LogID& id)
Matt Spinler475e5742019-07-18 16:09:49 -0500211{
Matt Spinler52602e32020-07-15 12:37:28 -0500212 std::optional<LogID> actualID;
213
Matt Spinler475e5742019-07-18 16:09:49 -0500214 auto pel = findPEL(id);
Matt Spinler0ff00482019-11-06 16:19:46 -0600215 if (pel != _pelAttributes.end())
Matt Spinler475e5742019-07-18 16:09:49 -0500216 {
Matt Spinler52602e32020-07-15 12:37:28 -0500217 actualID = pel->first;
Matt Spinlerb188f782020-07-07 11:18:12 -0500218 updateRepoStats(pel->second, false);
219
Matt Spinler5f5352e2020-03-05 16:23:27 -0600220 log<level::DEBUG>("Removing PEL from repository",
221 entry("PEL_ID=0x%X", pel->first.pelID.id),
222 entry("OBMC_LOG_ID=%d", pel->first.obmcID.id));
Matt Spinler0ff00482019-11-06 16:19:46 -0600223 fs::remove(pel->second.path);
224 _pelAttributes.erase(pel);
Matt Spinler421f6532019-11-06 15:40:45 -0600225
Matt Spinler5f5352e2020-03-05 16:23:27 -0600226 processDeleteCallbacks(pel->first.pelID.id);
227 }
Matt Spinler52602e32020-07-15 12:37:28 -0500228
229 return actualID;
Matt Spinler89fa0822019-07-17 13:54:30 -0500230}
231
Matt Spinler2813f362019-07-19 12:45:28 -0500232std::optional<std::vector<uint8_t>> Repository::getPELData(const LogID& id)
233{
234 auto pel = findPEL(id);
Matt Spinler0ff00482019-11-06 16:19:46 -0600235 if (pel != _pelAttributes.end())
Matt Spinler2813f362019-07-19 12:45:28 -0500236 {
Matt Spinler0ff00482019-11-06 16:19:46 -0600237 std::ifstream file{pel->second.path.c_str()};
Matt Spinler2813f362019-07-19 12:45:28 -0500238 if (!file.good())
239 {
240 auto e = errno;
241 log<level::ERR>("Unable to open PEL file", entry("ERRNO=%d", e),
Matt Spinler0ff00482019-11-06 16:19:46 -0600242 entry("PATH=%s", pel->second.path.c_str()));
Matt Spinler2813f362019-07-19 12:45:28 -0500243 throw file_error::Open();
244 }
245
246 std::vector<uint8_t> data{std::istreambuf_iterator<char>(file),
247 std::istreambuf_iterator<char>()};
248 return data;
249 }
250
251 return std::nullopt;
252}
253
Matt Spinler6d512242019-12-09 13:44:17 -0600254std::optional<sdbusplus::message::unix_fd> Repository::getPELFD(const LogID& id)
255{
256 auto pel = findPEL(id);
257 if (pel != _pelAttributes.end())
258 {
259 FILE* fp = fopen(pel->second.path.c_str(), "rb");
260
261 if (fp == nullptr)
262 {
263 auto e = errno;
264 log<level::ERR>("Unable to open PEL File", entry("ERRNO=%d", e),
265 entry("PATH=%s", pel->second.path.c_str()));
266 throw file_error::Open();
267 }
268
269 // Must leave the file open here. It will be closed by sdbusplus
270 // when it sends it back over D-Bus.
271
272 return fileno(fp);
273 }
274 return std::nullopt;
275}
276
Matt Spinler1ea78802019-11-01 13:04:59 -0500277void Repository::for_each(ForEachFunc func) const
278{
Matt Spinler0ff00482019-11-06 16:19:46 -0600279 for (const auto& [id, attributes] : _pelAttributes)
Matt Spinler1ea78802019-11-01 13:04:59 -0500280 {
Matt Spinler0ff00482019-11-06 16:19:46 -0600281 std::ifstream file{attributes.path};
Matt Spinler1ea78802019-11-01 13:04:59 -0500282
283 if (!file.good())
284 {
285 auto e = errno;
286 log<level::ERR>("Repository::for_each: Unable to open PEL file",
287 entry("ERRNO=%d", e),
Matt Spinler0ff00482019-11-06 16:19:46 -0600288 entry("PATH=%s", attributes.path.c_str()));
Matt Spinler1ea78802019-11-01 13:04:59 -0500289 continue;
290 }
291
292 std::vector<uint8_t> data{std::istreambuf_iterator<char>(file),
293 std::istreambuf_iterator<char>()};
294 file.close();
295
296 PEL pel{data};
297
298 try
299 {
300 if (func(pel))
301 {
302 break;
303 }
304 }
305 catch (std::exception& e)
306 {
307 log<level::ERR>("Repository::for_each function exception",
308 entry("ERROR=%s", e.what()));
309 }
310 }
311}
312
Matt Spinler421f6532019-11-06 15:40:45 -0600313void Repository::processAddCallbacks(const PEL& pel) const
314{
315 for (auto& [name, func] : _addSubscriptions)
316 {
317 try
318 {
319 func(pel);
320 }
321 catch (std::exception& e)
322 {
323 log<level::ERR>("PEL Repository add callback exception",
324 entry("NAME=%s", name.c_str()),
325 entry("ERROR=%s", e.what()));
326 }
327 }
328}
329
330void Repository::processDeleteCallbacks(uint32_t id) const
331{
332 for (auto& [name, func] : _deleteSubscriptions)
333 {
334 try
335 {
336 func(id);
337 }
338 catch (std::exception& e)
339 {
340 log<level::ERR>("PEL Repository delete callback exception",
341 entry("NAME=%s", name.c_str()),
342 entry("ERROR=%s", e.what()));
343 }
344 }
345}
346
Matt Spinler0ff00482019-11-06 16:19:46 -0600347std::optional<std::reference_wrapper<const Repository::PELAttributes>>
348 Repository::getPELAttributes(const LogID& id) const
349{
350 auto pel = findPEL(id);
351 if (pel != _pelAttributes.end())
352 {
353 return pel->second;
354 }
355
356 return std::nullopt;
357}
358
Matt Spinler29d18c12019-11-21 13:31:27 -0600359void Repository::setPELHostTransState(uint32_t pelID, TransmissionState state)
360{
361 LogID id{LogID::Pel{pelID}};
362 auto attr = std::find_if(_pelAttributes.begin(), _pelAttributes.end(),
363 [&id](const auto& a) { return a.first == id; });
364
365 if ((attr != _pelAttributes.end()) && (attr->second.hostState != state))
366 {
367 PELUpdateFunc func = [state](PEL& pel) {
368 pel.setHostTransmissionState(state);
369 };
370
371 try
372 {
373 updatePEL(attr->second.path, func);
374
375 attr->second.hostState = state;
376 }
377 catch (std::exception& e)
378 {
379 log<level::ERR>("Unable to update PEL host transmission state",
380 entry("PATH=%s", attr->second.path.c_str()),
381 entry("ERROR=%s", e.what()));
382 }
383 }
384}
385
386void Repository::setPELHMCTransState(uint32_t pelID, TransmissionState state)
387{
388 LogID id{LogID::Pel{pelID}};
389 auto attr = std::find_if(_pelAttributes.begin(), _pelAttributes.end(),
390 [&id](const auto& a) { return a.first == id; });
391
392 if ((attr != _pelAttributes.end()) && (attr->second.hmcState != state))
393 {
394 PELUpdateFunc func = [state](PEL& pel) {
395 pel.setHMCTransmissionState(state);
396 };
397
398 try
399 {
400 updatePEL(attr->second.path, func);
401
402 attr->second.hmcState = state;
403 }
404 catch (std::exception& e)
405 {
406 log<level::ERR>("Unable to update PEL HMC transmission state",
407 entry("PATH=%s", attr->second.path.c_str()),
408 entry("ERROR=%s", e.what()));
409 }
410 }
411}
412
413void Repository::updatePEL(const fs::path& path, PELUpdateFunc updateFunc)
414{
415 std::ifstream file{path};
416 std::vector<uint8_t> data{std::istreambuf_iterator<char>(file),
417 std::istreambuf_iterator<char>()};
418 file.close();
419
420 PEL pel{data};
421
422 if (pel.valid())
423 {
424 updateFunc(pel);
425
426 write(pel, path);
427 }
428 else
429 {
430 throw std::runtime_error(
431 "Unable to read a valid PEL when trying to update it");
432 }
433}
434
Matt Spinlerb188f782020-07-07 11:18:12 -0500435bool Repository::isServiceableSev(const PELAttributes& pel)
436{
437 auto sevType = static_cast<SeverityType>(pel.severity & 0xF0);
438 auto sevPVEntry =
439 pel_values::findByValue(pel.severity, pel_values::severityValues);
440 std::string sevName = std::get<pel_values::registryNamePos>(*sevPVEntry);
441
442 bool check1 = (sevType == SeverityType::predictive) ||
443 (sevType == SeverityType::unrecoverable) ||
444 (sevType == SeverityType::critical);
445
446 bool check2 = ((sevType == SeverityType::recovered) ||
447 (sevName == "symptom_recovered")) &&
448 !pel.actionFlags.test(hiddenFlagBit);
449
450 bool check3 = (sevName == "symptom_predictive") ||
451 (sevName == "symptom_unrecoverable") ||
452 (sevName == "symptom_critical");
453
454 return check1 || check2 || check3;
455}
456
457void Repository::updateRepoStats(const PELAttributes& pel, bool pelAdded)
458{
459 auto isServiceable = Repository::isServiceableSev(pel);
460 auto bmcPEL = CreatorID::openBMC == static_cast<CreatorID>(pel.creator);
461
462 auto adjustSize = [pelAdded, &pel](auto& runningSize) {
463 if (pelAdded)
464 {
465 runningSize += pel.sizeOnDisk;
466 }
467 else
468 {
469 runningSize = std::max(static_cast<int64_t>(runningSize) -
470 static_cast<int64_t>(pel.sizeOnDisk),
471 static_cast<int64_t>(0));
472 }
473 };
474
475 adjustSize(_sizes.total);
476
477 if (bmcPEL)
478 {
479 adjustSize(_sizes.bmc);
480 if (isServiceable)
481 {
482 adjustSize(_sizes.bmcServiceable);
483 }
484 else
485 {
486 adjustSize(_sizes.bmcInfo);
487 }
488 }
489 else
490 {
491 adjustSize(_sizes.nonBMC);
492 if (isServiceable)
493 {
494 adjustSize(_sizes.nonBMCServiceable);
495 }
496 else
497 {
498 adjustSize(_sizes.nonBMCInfo);
499 }
500 }
501}
502
Matt Spinler7e727a32020-07-07 15:00:17 -0500503bool Repository::sizeWarning() const
504{
505 return (_sizes.total > (_maxRepoSize * warningPercentage / 100)) ||
506 (_pelAttributes.size() > _maxNumPELs);
507}
508
Matt Spinlerb0a8df52020-07-07 14:41:06 -0500509std::vector<Repository::AttributesReference>
510 Repository::getAllPELAttributes(SortOrder order) const
511{
512 std::vector<Repository::AttributesReference> attributes;
513
514 std::for_each(
515 _pelAttributes.begin(), _pelAttributes.end(),
516 [&attributes](auto& pelEntry) { attributes.push_back(pelEntry); });
517
518 std::sort(attributes.begin(), attributes.end(),
519 [order](const auto& left, const auto& right) {
520 if (order == SortOrder::ascending)
521 {
522 return left.get().second.path < right.get().second.path;
523 }
524 return left.get().second.path > right.get().second.path;
525 });
526
527 return attributes;
528}
529
530std::vector<uint32_t> Repository::prune()
531{
532 std::vector<uint32_t> obmcLogIDs;
533 std::string msg = "Pruning PEL repository that takes up " +
534 std::to_string(_sizes.total) + " bytes and has " +
535 std::to_string(_pelAttributes.size()) + " PELs";
536 log<level::INFO>(msg.c_str());
537
538 // Set up the 5 functions to check if the PEL category
539 // is still over its limits.
540
541 // BMC informational PELs should only take up 15%
542 IsOverLimitFunc overBMCInfoLimit = [this]() {
543 return _sizes.bmcInfo > _maxRepoSize * 15 / 100;
544 };
545
546 // BMC non informational PELs should only take up 30%
547 IsOverLimitFunc overBMCNonInfoLimit = [this]() {
548 return _sizes.bmcServiceable > _maxRepoSize * 30 / 100;
549 };
550
551 // Non BMC informational PELs should only take up 15%
552 IsOverLimitFunc overNonBMCInfoLimit = [this]() {
553 return _sizes.nonBMCInfo > _maxRepoSize * 15 / 100;
554 };
555
556 // Non BMC non informational PELs should only take up 15%
557 IsOverLimitFunc overNonBMCNonInfoLimit = [this]() {
558 return _sizes.nonBMCServiceable > _maxRepoSize * 30 / 100;
559 };
560
561 // Bring the total number of PELs down to 80% of the max
562 IsOverLimitFunc tooManyPELsLimit = [this]() {
563 return _pelAttributes.size() > _maxNumPELs * 80 / 100;
564 };
565
566 // Set up the functions to determine which category a PEL is in.
567 // TODO: Return false in these functions if a PEL caused a guard record.
568
569 // A BMC informational PEL
570 IsPELTypeFunc isBMCInfo = [](const PELAttributes& pel) {
571 return (CreatorID::openBMC == static_cast<CreatorID>(pel.creator)) &&
572 !Repository::isServiceableSev(pel);
573 };
574
575 // A BMC non informational PEL
576 IsPELTypeFunc isBMCNonInfo = [](const PELAttributes& pel) {
577 return (CreatorID::openBMC == static_cast<CreatorID>(pel.creator)) &&
578 Repository::isServiceableSev(pel);
579 };
580
581 // A non BMC informational PEL
582 IsPELTypeFunc isNonBMCInfo = [](const PELAttributes& pel) {
583 return (CreatorID::openBMC != static_cast<CreatorID>(pel.creator)) &&
584 !Repository::isServiceableSev(pel);
585 };
586
587 // A non BMC non informational PEL
588 IsPELTypeFunc isNonBMCNonInfo = [](const PELAttributes& pel) {
589 return (CreatorID::openBMC != static_cast<CreatorID>(pel.creator)) &&
590 Repository::isServiceableSev(pel);
591 };
592
593 // When counting PELs, count every PEL
594 IsPELTypeFunc isAnyPEL = [](const PELAttributes& pel) { return true; };
595
596 // Check all 4 categories, which will result in at most 90%
597 // usage (15 + 30 + 15 + 30).
598 removePELs(overBMCInfoLimit, isBMCInfo, obmcLogIDs);
599 removePELs(overBMCNonInfoLimit, isBMCNonInfo, obmcLogIDs);
600 removePELs(overNonBMCInfoLimit, isNonBMCInfo, obmcLogIDs);
601 removePELs(overNonBMCNonInfoLimit, isNonBMCNonInfo, obmcLogIDs);
602
603 // After the above pruning check if there are still too many PELs,
604 // which can happen depending on PEL sizes.
605 if (_pelAttributes.size() > _maxNumPELs)
606 {
607 removePELs(tooManyPELsLimit, isAnyPEL, obmcLogIDs);
608 }
609
610 if (!obmcLogIDs.empty())
611 {
612 std::string msg = "Number of PELs removed to save space: " +
613 std::to_string(obmcLogIDs.size());
614 log<level::INFO>(msg.c_str());
615 }
616
617 return obmcLogIDs;
618}
619
620void Repository::removePELs(IsOverLimitFunc& isOverLimit,
621 IsPELTypeFunc& isPELType,
622 std::vector<uint32_t>& removedBMCLogIDs)
623{
624 if (!isOverLimit())
625 {
626 return;
627 }
628
629 auto attributes = getAllPELAttributes(SortOrder::ascending);
630
631 // Make 4 passes on the PELs, stopping as soon as isOverLimit
632 // returns false.
633 // Pass 1: only delete HMC acked PELs
634 // Pass 2: only delete OS acked PELs
635 // Pass 3: only delete PHYP sent PELs
636 // Pass 4: delete all PELs
637 static const std::vector<std::function<bool(const PELAttributes& pel)>>
638 stateChecks{[](const auto& pel) {
639 return pel.hmcState == TransmissionState::acked;
640 },
641
642 [](const auto& pel) {
643 return pel.hostState == TransmissionState::acked;
644 },
645
646 [](const auto& pel) {
647 return pel.hostState == TransmissionState::sent;
648 },
649
650 [](const auto& pel) { return true; }};
651
652 for (const auto& stateCheck : stateChecks)
653 {
654 for (auto it = attributes.begin(); it != attributes.end();)
655 {
656 const auto& pel = it->get();
657 if (isPELType(pel.second) && stateCheck(pel.second))
658 {
659 auto removedID = pel.first.obmcID.id;
660 remove(pel.first);
661
662 removedBMCLogIDs.push_back(removedID);
663
664 attributes.erase(it);
665
666 if (!isOverLimit())
667 {
668 break;
669 }
670 }
671 else
672 {
673 ++it;
674 }
675 }
676
677 if (!isOverLimit())
678 {
679 break;
680 }
681 }
682}
683
Matt Spinler89fa0822019-07-17 13:54:30 -0500684} // namespace pels
685} // namespace openpower