attn: Move create pel support to util
Move the create pel support from attention handler the util library.
Signed-off-by: Ben Tyner <ben.tyner@ibm.com>
Change-Id: I023add4b3e237d0253b218ff2912ea081961da6d
diff --git a/attn/attn_dbus.cpp b/attn/attn_dbus.cpp
index e4ad47a..2d11bde 100644
--- a/attn/attn_dbus.cpp
+++ b/attn/attn_dbus.cpp
@@ -50,51 +50,6 @@
return rc;
}
-/** @brief Create a PEL for the specified event type */
-uint32_t createPel(const std::string& i_event,
- std::map<std::string, std::string>& i_additional,
- const std::vector<util::FFDCTuple>& i_ffdc)
-{
- // CreatePELWithFFDCFiles returns plid
- int plid = 0;
-
- // Need to provide pid when using create or create-with-ffdc methods
- i_additional.emplace("_PID", std::to_string(getpid()));
-
- // Sdbus call specifics
- constexpr auto interface = "org.open_power.Logging.PEL";
- constexpr auto function = "CreatePELWithFFDCFiles";
-
- sdbusplus::message::message method;
-
- if (0 == dbusMethod(pathLogging, interface, function, method))
- {
- try
- {
- // append additional dbus call paramaters
- method.append(i_event, levelPelError, i_additional, i_ffdc);
-
- // using system dbus
- auto bus = sdbusplus::bus::new_system();
- auto response = bus.call(method);
-
- // reply will be tuple containing bmc log id, platform log id
- std::tuple<uint32_t, uint32_t> reply = {0, 0};
-
- // parse dbus response into reply
- response.read(reply);
- plid = std::get<1>(reply); // platform log id is tuple "second"
- }
- catch (const sdbusplus::exception::SdBusError& e)
- {
- trace::err("createPel exception");
- trace::err(e.what());
- }
- }
-
- return plid; // platform log id or 0
-}
-
/** @brief Create a PEL from raw PEL data */
void createPelRaw(const std::vector<uint8_t>& i_buffer)
{
diff --git a/attn/attn_dbus.hpp b/attn/attn_dbus.hpp
index 2d72740..b01c82d 100644
--- a/attn/attn_dbus.hpp
+++ b/attn/attn_dbus.hpp
@@ -26,24 +26,6 @@
sdbusplus::message::message& o_method);
/**
- * Create a PEL for the specified event type
- *
- * The additional data provided in the map will be placed in a user data
- * section of the PEL and may additionally contain key words to trigger
- * certain behaviors by the backend logging code. Each set of data described
- * in the vector of ffdc data will be placed in additional user data
- * sections.
- *
- * @param i_event - the event type
- * @param i_additional - map of additional data
- * @param i_ffdc - vector of ffdc data
- * @return Platform log id or 0 if error
- */
-uint32_t createPel(const std::string& i_event,
- std::map<std::string, std::string>& i_additional,
- const std::vector<util::FFDCTuple>& i_ffdc);
-
-/**
* Create a PEL from raw PEL data
*
* Create a PEL based on the pel defined in the data buffer specified.
diff --git a/attn/attn_handler.cpp b/attn/attn_handler.cpp
index 79c5e2b..175ce56 100644
--- a/attn/attn_handler.cpp
+++ b/attn/attn_handler.cpp
@@ -478,8 +478,8 @@
static_cast<uint8_t>(0x01), fd}};
// Create event log entry with FFDC data
- createPel("org.open_power.Processor.Error.SbeChipOpFailure",
- additionalData, ffdc);
+ util::dbus::createPel("org.open_power.Processor.Error.SbeChipOpFailure",
+ levelPelError, additionalData, ffdc);
}
}
#endif
diff --git a/attn/attn_logging.cpp b/attn/attn_logging.cpp
index 226b496..52e39bc 100644
--- a/attn/attn_logging.cpp
+++ b/attn/attn_logging.cpp
@@ -7,6 +7,7 @@
#include <attn/attn_logging.hpp>
#include <attn/pel/pel_minimal.hpp>
#include <phosphor-logging/log.hpp>
+#include <util/dbus.hpp>
#include <util/ffdc.hpp>
#include <util/trace.hpp>
@@ -291,7 +292,8 @@
{
// Create PEL with additional data and FFDC data. The newly created
// PEL's platform log-id will be returned.
- pelId = createPel(eventName, i_additional, createFFDCTuples(i_ffdc));
+ pelId = util::dbus::createPel(eventName, levelPelError, i_additional,
+ createFFDCTuples(i_ffdc));
// If this is a TI event we will create an additional PEL that is
// specific to the subsystem that generated the TI.
diff --git a/util/dbus.cpp b/util/dbus.cpp
index 4f28154..ea3fdf0 100644
--- a/util/dbus.cpp
+++ b/util/dbus.cpp
@@ -303,6 +303,58 @@
return dumpPolicyEnabled;
}
+/** @brief Create a PEL */
+uint32_t createPel(const std::string& i_message, const std::string& i_severity,
+ std::map<std::string, std::string>& io_additional,
+ const std::vector<util::FFDCTuple>& i_ffdc)
+{
+ // CreatePELWithFFDCFiles returns plid
+ int plid = 0;
+
+ // Sdbus call specifics
+ constexpr auto interface = "org.open_power.Logging.PEL";
+ constexpr auto path = "/xyz/openbmc_project/logging";
+
+ // we need to find the service implementing the interface
+ util::dbus::DBusService service;
+
+ if (0 == findService(interface, path, service))
+ {
+ try
+ {
+ constexpr auto function = "CreatePELWithFFDCFiles";
+
+ // The "Create" method requires manually adding the process ID.
+ io_additional["_PID"] = std::to_string(getpid());
+
+ // create dbus method
+ auto bus = sdbusplus::bus::new_system();
+ sdbusplus::message::message method =
+ bus.new_method_call(service.c_str(), path, interface, function);
+
+ // append additional dbus call paramaters
+ method.append(i_message, i_severity, io_additional, i_ffdc);
+
+ // using system dbus
+ auto response = bus.call(method);
+
+ // reply will be tuple containing bmc log id, platform log id
+ std::tuple<uint32_t, uint32_t> reply = {0, 0};
+
+ // parse dbus response into reply
+ response.read(reply);
+ plid = std::get<1>(reply); // platform log id is tuple "second"
+ }
+ catch (const sdbusplus::exception::SdBusError& e)
+ {
+ trace::err("createPel exception");
+ trace::err(e.what());
+ }
+ }
+
+ return plid; // platform log id or 0
+}
+
} // namespace dbus
} // namespace util
diff --git a/util/dbus.hpp b/util/dbus.hpp
index ecc8d13..fc8f11a 100644
--- a/util/dbus.hpp
+++ b/util/dbus.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <sdbusplus/bus.hpp>
+#include <util/ffdc_file.hpp>
#include <string>
#include <variant>
@@ -113,6 +114,26 @@
*/
bool dumpPolicyEnabled();
+/**
+ * Create a PEL
+ *
+ * The additional data provided in the map will be placed in a user data
+ * section of the PEL and may additionally contain key words to trigger
+ * certain behaviors by the backend logging code. Each set of data described
+ * in the vector of ffdc data will be placed in additional user data
+ * sections. Note that the PID of the caller will be added to the additional
+ * data map with key "_PID".
+ *
+ * @param i_message - the event type
+ * @param i_severity - the severity level
+ * @param io_additional - map of additional data
+ * @param i_ffdc - vector of ffdc data
+ * @return Platform log id or 0 if error
+ */
+uint32_t createPel(const std::string& i_message, const std::string& i_severity,
+ std::map<std::string, std::string>& io_additional,
+ const std::vector<FFDCTuple>& i_ffdc);
+
} // namespace dbus
} // namespace util