OpenPOWER: Limit User-Requested System Dumps

System dumps can be several gigabytes in size. To conserve space,
only one dump is stored at a time. When a new dump is requested,
the existing dump will be discarded while creating a new one.
In the case of system-generated dumps, which are triggered by
critical errors, it is permissible to initiate a new dump even
if an existing dump is already present in the host memory
This commit adds a restriction on initiating new user-requested system
dumps while a system dump is in progress or if one is already stored
in host memory.

New user-requested system dumps will be allowed once the existing
dump is deleted or offloaded.

This change applies only to user-requested dumps and does not impact
system generated dumps.

Test:
- Initiate system dump when another dump in progress and verified
  a Unavailable was returned
- Force a system generated system dump when one dump is present
  a Unavailable was returned

Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
Change-Id: I4598912b0761669859f84a43ab4c60f47664b1e6
diff --git a/dump-extensions/openpower-dumps/dump_manager_system.cpp b/dump-extensions/openpower-dumps/dump_manager_system.cpp
index fad4947..949c87c 100644
--- a/dump-extensions/openpower-dumps/dump_manager_system.cpp
+++ b/dump-extensions/openpower-dumps/dump_manager_system.cpp
@@ -4,6 +4,7 @@
 
 #include "dump_utils.hpp"
 #include "op_dump_consts.hpp"
+#include "op_dump_util.hpp"
 #include "system_dump_entry.hpp"
 #include "xyz/openbmc_project/Common/error.hpp"
 
@@ -140,6 +141,14 @@
         lg2::warning(
             "System dump accepts not more than 2 additional parameters");
     }
+    using Unavailable =
+        sdbusplus::xyz::openbmc_project::Common::Error::Unavailable;
+
+    if (openpower::dump::util::isSystemDumpInProgress(bus))
+    {
+        lg2::error("Another dump in progress or available to offload");
+        elog<Unavailable>();
+    }
 
     using NotAllowed =
         sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;