PEL: Deleted PELs moved to new folder under logs
- PELs whose corresponding event logs have been deleted
will be available in the archive folder.
- Archive folder size is tracked under sizeWarning() function.
- Archived PELs log can be viewed using peltool with flag --archive.
- PELs deleted using peltool is not archived.
- Updated README.md
Change-Id: Ie2c1b4c2ca30fb79904bc9d582a01ef8102aed0e
Signed-off-by: Sumit Kumar <sumit_kumar@in.ibm.com>
diff --git a/extensions/openpower-pels/repository.cpp b/extensions/openpower-pels/repository.cpp
index fd5c238..f552a75 100644
--- a/extensions/openpower-pels/repository.cpp
+++ b/extensions/openpower-pels/repository.cpp
@@ -61,13 +61,19 @@
Repository::Repository(const std::filesystem::path& basePath, size_t repoSize,
size_t maxNumPELs) :
_logPath(basePath / "logs"),
- _maxRepoSize(repoSize), _maxNumPELs(maxNumPELs)
+ _maxRepoSize(repoSize), _maxNumPELs(maxNumPELs),
+ _archivePath(basePath / "logs" / "archive")
{
if (!fs::exists(_logPath))
{
fs::create_directories(_logPath);
}
+ if (!fs::exists(_archivePath))
+ {
+ fs::create_directories(_archivePath);
+ }
+
restore();
}
@@ -138,6 +144,12 @@
entry("ERROR=%s", e.what()));
}
}
+
+ // Get size of archive folder
+ for (auto& dirEntry : fs::directory_iterator(_archivePath))
+ {
+ _archiveSize += getFileDiskSize(dirEntry);
+ }
}
std::string Repository::getPELFilename(uint32_t pelID, const BCDTime& time)
@@ -223,7 +235,23 @@
log<level::DEBUG>("Removing PEL from repository",
entry("PEL_ID=0x%X", actualID.pelID.id),
entry("OBMC_LOG_ID=%d", actualID.obmcID.id));
- fs::remove(pel->second.path);
+
+ if (fs::exists(pel->second.path))
+ {
+ // Check for existense of new archive folder
+ if (!fs::exists(_archivePath))
+ {
+ fs::create_directories(_archivePath);
+ }
+
+ // Move log file to archive folder
+ auto fileName = _archivePath / pel->second.path.filename();
+ fs::rename(pel->second.path, fileName);
+
+ // Update size of file
+ _archiveSize += getFileDiskSize(fileName);
+ }
+
_pelAttributes.erase(pel);
processDeleteCallbacks(actualID.pelID.id);
@@ -504,6 +532,21 @@
bool Repository::sizeWarning() const
{
+ if ((_archiveSize > 0) && ((_sizes.total + _archiveSize) >
+ ((_maxRepoSize * warningPercentage) / 100)))
+ {
+ log<level::INFO>(
+ "Repository::sizeWarning function:Deleting the files in archive");
+
+ std::string cmd = "rm " + _archivePath.string() + "/*_*";
+ auto rc = system(cmd.c_str());
+ if (rc)
+ {
+ log<level::ERR>("Repository::sizeWarning function:Could not delete "
+ "files in archive");
+ }
+ }
+
return (_sizes.total > (_maxRepoSize * warningPercentage / 100)) ||
(_pelAttributes.size() > _maxNumPELs);
}