summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2019-11-07 13:38:07 -0600
committerMatt Spinler <spinler@us.ibm.com>2019-12-09 13:47:57 -0600
commitab1b97fe0af268c98113dd474443f28253ba9ddd (patch)
tree725cb904b4cff3d1b14c82f18b3ce3a6e9406b76 /extensions
parentf38ce984a435299c4c6f60e7222941fdc25f18ac (diff)
downloadphosphor-logging-ab1b97fe0af268c98113dd474443f28253ba9ddd.tar.gz
phosphor-logging-ab1b97fe0af268c98113dd474443f28253ba9ddd.zip
PEL: Repository: Add write() function
Pull the code that writes a PEL object to a file into a separate function so that it can be called in multiple places. Signed-off-by: Matt Spinler <spinler@us.ibm.com> Change-Id: Ic5701fdfb03cca915520222bbbd8bb92a9c47c49
Diffstat (limited to 'extensions')
-rw-r--r--extensions/openpower-pels/repository.cpp28
-rw-r--r--extensions/openpower-pels/repository.hpp10
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;
OpenPOWER on IntegriCloud