diff options
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/openpower-pels/repository.cpp | 28 | ||||
-rw-r--r-- | extensions/openpower-pels/repository.hpp | 10 |
2 files changed, 26 insertions, 12 deletions
diff --git a/extensions/openpower-pels/repository.cpp b/extensions/openpower-pels/repository.cpp index 93d2f81..3aeecb6 100644 --- a/extensions/openpower-pels/repository.cpp +++ b/extensions/openpower-pels/repository.cpp @@ -96,6 +96,21 @@ std::string Repository::getPELFilename(uint32_t pelID, const BCDTime& time) void Repository::add(std::unique_ptr<PEL>& pel) { auto path = _logPath / getPELFilename(pel->id(), pel->commitTime()); + + write(*(pel.get()), path); + + PELAttributes attributes{path, pel->userHeader().actionFlags()}; + + using pelID = LogID::Pel; + using obmcID = LogID::Obmc; + _pelAttributes.emplace(LogID(pelID(pel->id()), obmcID(pel->obmcLogID())), + attributes); + + processAddCallbacks(*pel); +} + +void Repository::write(const PEL& pel, const fs::path& path) +{ std::ofstream file{path, std::ios::binary}; if (!file.good()) @@ -109,7 +124,7 @@ void Repository::add(std::unique_ptr<PEL>& pel) throw file_error::Open(); } - auto data = pel->data(); + auto data = pel.data(); file.write(reinterpret_cast<const char*>(data.data()), data.size()); if (file.fail()) @@ -123,17 +138,6 @@ void Repository::add(std::unique_ptr<PEL>& pel) entry("PATH=%s", path.c_str())); throw file_error::Write(); } - - file.close(); - - PELAttributes attributes{path, pel->userHeader().actionFlags()}; - - using pelID = LogID::Pel; - using obmcID = LogID::Obmc; - _pelAttributes.emplace(LogID(pelID(pel->id()), obmcID(pel->obmcLogID())), - attributes); - - processAddCallbacks(*pel); } void Repository::remove(const LogID& id) diff --git a/extensions/openpower-pels/repository.hpp b/extensions/openpower-pels/repository.hpp index 5c31fed..0832f58 100644 --- a/extensions/openpower-pels/repository.hpp +++ b/extensions/openpower-pels/repository.hpp @@ -293,6 +293,16 @@ class Repository void restore(); /** + * @brief Stores a PEL object in the filesystem. + * + * @param[in] pel - The PEL to write + * @param[in] path - The file to write to + * + * Throws exceptions on failures. + */ + void write(const PEL& pel, const std::filesystem::path& path); + + /** * @brief The filesystem path to the PEL logs. */ const std::filesystem::path _logPath; |