Restore dump d-bus objects during daemon starts
Use the dump files in the persistant location to rebuild the
d-bus objects.
Change-Id: Ia7b478649274a4681c802e11be4b2049eeed8e13
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
diff --git a/dump_manager.cpp b/dump_manager.cpp
index 7e753c0..3775842 100644
--- a/dump_manager.cpp
+++ b/dump_manager.cpp
@@ -16,7 +16,6 @@
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
using namespace phosphor::logging;
-using namespace std;
namespace internal
{
@@ -170,5 +169,35 @@
childWatchMap.erase(path);
}
+void Manager::restore()
+{
+ fs::path dir(BMC_DUMP_PATH);
+ if (!fs::exists(dir) || fs::is_empty(dir))
+ {
+ return;
+ }
+
+ //Dump file path: <BMC_DUMP_PATH>/<id>/<filename>
+ for (const auto& p : fs::directory_iterator(dir))
+ {
+ auto idStr = p.path().filename().string();
+
+ //Consider only directory's with dump id as name.
+ //Note: As per design one file per directory.
+ if ((fs::is_directory(p.path())) &&
+ std::all_of(idStr.begin(), idStr.end(), ::isdigit))
+ {
+ lastEntryId = std::max(lastEntryId,
+ static_cast<uint32_t>(std::stoul(idStr)));
+ auto fileIt = fs::directory_iterator(p.path());
+ //Create dump entry d-bus object.
+ if (fileIt != fs::end(fileIt))
+ {
+ createEntry(fileIt->path());
+ }
+ }
+ }
+}
+
} //namespace dump
} //namespace phosphor
diff --git a/dump_manager.hpp b/dump_manager.hpp
index 003d9e4..ea1a5ba 100644
--- a/dump_manager.hpp
+++ b/dump_manager.hpp
@@ -87,6 +87,11 @@
*/
void watchCallback(const UserMap& fileInfo);
+ /** @brief Construct dump d-bus objects from their persisted
+ * representations.
+ */
+ void restore();
+
private:
/** @brief Create Dump entry d-bus object
* @param[in] fullPath - Full path of the Dump file name
diff --git a/dump_manager_main.cpp b/dump_manager_main.cpp
index 89aa6d4..ade1073 100644
--- a/dump_manager_main.cpp
+++ b/dump_manager_main.cpp
@@ -33,6 +33,8 @@
try
{
phosphor::dump::Manager manager(bus, eventP, DUMP_OBJPATH);
+ //Restore dump d-bus objects.
+ manager.restore();
phosphor::dump::internal::Manager mgr(bus, manager, OBJ_INTERNAL);
bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL);