summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Joseph <tomjoseph@in.ibm.com>2017-06-30 19:12:49 +0530
committerPatrick Williams <patrick@stwcx.xyz>2017-07-19 19:54:41 +0000
commit8f4a2aa8ea9485d91babc139bc1c4d878b34b13b (patch)
tree9f1cb22fea21d5f9b793b926e3200ef4f230977f
parenta495339f39ace4f729f31f40e837f8d5b76732cb (diff)
downloadphosphor-host-ipmid-8f4a2aa8ea9485d91babc139bc1c4d878b34b13b.tar.gz
phosphor-host-ipmid-8f4a2aa8ea9485d91babc139bc1c4d878b34b13b.zip
Add Delete SEL entry command
Change-Id: Iabeaca4b5057ef1bae44cb6d30704de3ce2f1269 Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
-rw-r--r--selutility.hpp10
-rw-r--r--storagehandler.cpp92
-rw-r--r--storagehandler.h1
3 files changed, 103 insertions, 0 deletions
diff --git a/selutility.hpp b/selutility.hpp
index ddf003a..50babca 100644
--- a/selutility.hpp
+++ b/selutility.hpp
@@ -78,6 +78,16 @@ struct GetSELEntryResponse
uint8_t eventData3; //!< Event Data 3.
} __attribute__((packed));
+/** @struct DeleteSELEntryRequest
+ *
+ * IPMI payload for Delete SEL Entry command request.
+ */
+struct DeleteSELEntryRequest
+{
+ uint16_t reservationID; //!< Reservation ID.
+ uint16_t selRecordID; //!< SEL Record ID.
+} __attribute__((packed));
+
/** @brief Convert logging entry to SEL
*
* @param[in] objPath - DBUS object path of the logging entry.
diff --git a/storagehandler.cpp b/storagehandler.cpp
index 66db77b..cd6f10c 100644
--- a/storagehandler.cpp
+++ b/storagehandler.cpp
@@ -7,6 +7,7 @@
#include "selutility.hpp"
#include "storagehandler.h"
#include "storageaddsel.h"
+#include "utils.hpp"
#include "host-ipmid/ipmid-api.h"
#include <experimental/filesystem>
#include <phosphor-logging/log.hpp>
@@ -209,6 +210,92 @@ ipmi_ret_t getSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
return IPMI_CC_OK;
}
+ipmi_ret_t deleteSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
+ ipmi_request_t request, ipmi_response_t response,
+ ipmi_data_len_t data_len, ipmi_context_t context)
+{
+ namespace fs = std::experimental::filesystem;
+ auto requestData = reinterpret_cast<const ipmi::sel::DeleteSELEntryRequest*>
+ (request);
+
+ if (g_sel_reserve != requestData->reservationID)
+ {
+ *data_len = 0;
+ return IPMI_CC_INVALID_RESERVATION_ID;
+ }
+
+ ipmi::sel::readLoggingObjectPaths(cache::paths);
+
+ if (cache::paths.empty())
+ {
+ *data_len = 0;
+ return IPMI_CC_SENSOR_INVALID;
+ }
+
+ ipmi::sel::ObjectPaths::const_iterator iter;
+ uint16_t delRecordID = 0;
+
+ if (requestData->selRecordID == ipmi::sel::firstEntry)
+ {
+ iter = cache::paths.begin();
+ fs::path path(*iter);
+ delRecordID = static_cast<uint16_t>
+ (std::stoul(std::string(path.filename().c_str())));
+ }
+ else if (requestData->selRecordID == ipmi::sel::lastEntry)
+ {
+ iter = cache::paths.end();
+ fs::path path(*iter);
+ delRecordID = static_cast<uint16_t>
+ (std::stoul(std::string(path.filename().c_str())));
+ }
+ else
+ {
+ std::string objPath = std::string(ipmi::sel::logBasePath) + "/" +
+ std::to_string(requestData->selRecordID);
+
+ iter = std::find(cache::paths.begin(), cache::paths.end(), objPath);
+ if (iter == cache::paths.end())
+ {
+ *data_len = 0;
+ return IPMI_CC_SENSOR_INVALID;
+ }
+ delRecordID = requestData->selRecordID;
+ }
+
+ sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
+ std::string service;
+
+ try
+ {
+ service = ipmi::getService(bus, ipmi::sel::logDeleteIntf, *iter);
+ }
+ catch (const std::runtime_error& e)
+ {
+ log<level::ERR>(e.what());
+ *data_len = 0;
+ return IPMI_CC_UNSPECIFIED_ERROR;
+ }
+
+ auto methodCall = bus.new_method_call(service.c_str(),
+ (*iter).c_str(),
+ ipmi::sel::logDeleteIntf,
+ "Delete");
+ auto reply = bus.call(methodCall);
+ if (reply.is_method_error())
+ {
+ *data_len = 0;
+ return IPMI_CC_UNSPECIFIED_ERROR;
+ }
+
+ // Invalidate the cache of dbus entry objects.
+ cache::paths.clear();
+ memcpy(response, &delRecordID, sizeof(delRecordID));
+ *data_len = sizeof(delRecordID);
+
+ return IPMI_CC_OK;
+}
+
ipmi_ret_t ipmi_storage_get_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
ipmi_request_t request, ipmi_response_t response,
ipmi_data_len_t data_len, ipmi_context_t context)
@@ -420,6 +507,11 @@ void register_netfn_storage_functions()
ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY, NULL, getSELEntry,
PRIVILEGE_USER);
+ // <Delete SEL Entry>
+ printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_DELETE_SEL);
+ ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_DELETE_SEL, NULL, deleteSELEntry,
+ PRIVILEGE_OPERATOR);
+
// <Add SEL Entry>
printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_ADD_SEL);
ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_ADD_SEL, NULL, ipmi_storage_add_sel,
diff --git a/storagehandler.h b/storagehandler.h
index 2bfc172..e39d676 100644
--- a/storagehandler.h
+++ b/storagehandler.h
@@ -9,6 +9,7 @@ enum ipmi_netfn_storage_cmds
IPMI_CMD_RESERVE_SEL = 0x42,
IPMI_CMD_GET_SEL_ENTRY = 0x43,
IPMI_CMD_ADD_SEL = 0x44,
+ IPMI_CMD_DELETE_SEL = 0x46,
IPMI_CMD_GET_SEL_TIME = 0x48,
IPMI_CMD_SET_SEL_TIME = 0x49,
OpenPOWER on IntegriCloud