OpenPOWER: Do not remove InProgress system dump entrty during mp reboot

When the system dump is initiated by user a system dump
entry will be created with status as in progress. During
a power off all the entries of dumps stored in the host
memory needs to be removed except the entry created for
the system dump which causes the memory preserving
reboot.

Tests:
Manually initiate a system dump and make sure
dump is completed with same dump path as
returned during the create command.

Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
Change-Id: Ib75353b6d359b0af85cd2365da91dd5a673e92c6
diff --git a/dump-extensions/openpower-dumps/clear_hostdumps_poweroff.service b/dump-extensions/openpower-dumps/clear_hostdumps_poweroff.service
index f1dd0d3..3673c84 100644
--- a/dump-extensions/openpower-dumps/clear_hostdumps_poweroff.service
+++ b/dump-extensions/openpower-dumps/clear_hostdumps_poweroff.service
@@ -5,7 +5,6 @@
 Wants=obmc-host-stopping@0.target
 Before=obmc-host-stopping@0.target
 Conflicts=obmc-host-startmin@0.target
-ConditionPathExists=!/run/openbmc/mpreboot@0
 
 [Service]
 Type=oneshot
diff --git a/dump-extensions/openpower-dumps/op_dump_util.cpp b/dump-extensions/openpower-dumps/op_dump_util.cpp
index 14377a6..88d41ab 100644
--- a/dump-extensions/openpower-dumps/op_dump_util.cpp
+++ b/dump-extensions/openpower-dumps/op_dump_util.cpp
@@ -17,6 +17,9 @@
 {
 namespace util
 {
+
+constexpr auto MP_REBOOT_FILE = "/run/openbmc/mpreboot@0";
+
 using namespace phosphor::logging;
 using InternalFailure =
     sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
@@ -62,6 +65,11 @@
     log<level::INFO>("OpenPOWER dumps are enabled");
 }
 
+bool isInMpReboot()
+{
+    return std::filesystem::exists(MP_REBOOT_FILE);
+}
+
 } // namespace util
 } // namespace dump
 } // namespace openpower
diff --git a/dump-extensions/openpower-dumps/op_dump_util.hpp b/dump-extensions/openpower-dumps/op_dump_util.hpp
index 7a9f66a..3de441a 100644
--- a/dump-extensions/openpower-dumps/op_dump_util.hpp
+++ b/dump-extensions/openpower-dumps/op_dump_util.hpp
@@ -18,6 +18,12 @@
  */
 void isOPDumpsEnabled();
 
+/** @brief Check whether memory preserving reboot is in progress
+ *  @return true - memory preserving reboot in progress
+ *          false - no memory preserving reboot is going on
+ */
+bool isInMpReboot();
+
 } // namespace util
 } // namespace dump
 } // namespace openpower
diff --git a/dump-extensions/openpower-dumps/system_dump_entry.cpp b/dump-extensions/openpower-dumps/system_dump_entry.cpp
index 39b161d..63a23fc 100644
--- a/dump-extensions/openpower-dumps/system_dump_entry.cpp
+++ b/dump-extensions/openpower-dumps/system_dump_entry.cpp
@@ -3,6 +3,7 @@
 #include "dump_utils.hpp"
 #include "host_transport_exts.hpp"
 #include "op_dump_consts.hpp"
+#include "op_dump_util.hpp"
 
 #include <fmt/core.h>
 
@@ -25,7 +26,7 @@
 {
     log<level::INFO>(
         fmt::format(
-            "System dump offload request id({}) uri({}) source dumpid()", id,
+            "System dump offload request id({}) uri({}) source dumpid({})", id,
             uri, sourceDumpId())
             .c_str());
     phosphor::dump::Entry::initiateOffload(uri);
@@ -48,6 +49,19 @@
                 "Dump offload is in progress"));
     }
 
+    // Skip the system dump delete if the dump is in progress
+    // and in memory preserving reboot path
+    if ((openpower::dump::util::isInMpReboot()) &&
+        (status() == phosphor::dump::OperationStatus::InProgress))
+    {
+        log<level::INFO>(
+            fmt::format(
+                "Skip deleting system dump delete id({}) durng mp reboot",
+                dumpId)
+                .c_str());
+        return;
+    }
+
     log<level::INFO>(fmt::format("System dump delete id({}) srcdumpid({})",
                                  dumpId, srcDumpID)
                          .c_str());