diff options
author | Pradeep Kumar <pradeep1x.kumar@intel.com> | 2019-04-26 17:04:28 +0000 |
---|---|---|
committer | Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com> | 2019-05-03 03:28:39 +0000 |
commit | 00a18d040be228bb77c322db26cc3d53c8579a50 (patch) | |
tree | 01a6a7e1d219d698ae65dc6b3302eee84ce6e263 /storagehandler.cpp | |
parent | 5d06cc6dfee3aa0c42bb181dd7e050f4f8f8dd1e (diff) | |
download | phosphor-host-ipmid-00a18d040be228bb77c322db26cc3d53c8579a50.tar.gz phosphor-host-ipmid-00a18d040be228bb77c322db26cc3d53c8579a50.zip |
storagehandler: move delete SEL to new API
Rewritten "Delete SEL" command to use the newly
introduced IPMI provider API.
Tested:
Verified the behavior to be same as previous change.
ipmitool sel delete 5
Unable to delete entry 5: Requested sensor, data,
or record not found
Change-Id: I3b40be056ed1c9b3bb5ac75387c694abe16403b5
Signed-off-by: Pradeep Kumar <pradeep1x.kumar@intel.com>
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
Diffstat (limited to 'storagehandler.cpp')
-rw-r--r-- | storagehandler.cpp | 58 |
1 files changed, 26 insertions, 32 deletions
diff --git a/storagehandler.cpp b/storagehandler.cpp index c225279..2e89de7 100644 --- a/storagehandler.cpp +++ b/storagehandler.cpp @@ -267,24 +267,24 @@ 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) +/** @brief implements the delete SEL entry command + * @request + * - reservationID; // reservation ID. + * - selRecordID; // SEL record ID. + * + * @returns ipmi completion code plus response data + * - Record ID of the deleted record + */ +ipmi::RspType<uint16_t // deleted record ID + > + deleteSELEntry(uint16_t reservationID, uint16_t selRecordID) { - if (*data_len != sizeof(ipmi::sel::DeleteSELEntryRequest)) - { - *data_len = 0; - return IPMI_CC_REQ_DATA_LEN_INVALID; - } namespace fs = std::filesystem; - auto requestData = - reinterpret_cast<const ipmi::sel::DeleteSELEntryRequest*>(request); - if (!checkSELReservation(requestData->reservationID)) + if (!checkSELReservation(reservationID)) { - *data_len = 0; - return IPMI_CC_INVALID_RESERVATION_ID; + return ipmi::responseInvalidReservationId(); } // Per the IPMI spec, need to cancel the reservation when a SEL entry is @@ -299,27 +299,25 @@ ipmi_ret_t deleteSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd, { // readLoggingObjectPaths will throw exception if there are no error // log entries. - *data_len = 0; - return IPMI_CC_SENSOR_INVALID; + return ipmi::responseSensorInvalid(); } if (cache::paths.empty()) { - *data_len = 0; - return IPMI_CC_SENSOR_INVALID; + return ipmi::responseSensorInvalid(); } ipmi::sel::ObjectPaths::const_iterator iter; uint16_t delRecordID = 0; - if (requestData->selRecordID == ipmi::sel::firstEntry) + if (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) + else if (selRecordID == ipmi::sel::lastEntry) { iter = cache::paths.end(); fs::path path(*iter); @@ -329,15 +327,14 @@ ipmi_ret_t deleteSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd, else { std::string objPath = std::string(ipmi::sel::logBasePath) + "/" + - std::to_string(requestData->selRecordID); + std::to_string(selRecordID); iter = std::find(cache::paths.begin(), cache::paths.end(), objPath); if (iter == cache::paths.end()) { - *data_len = 0; - return IPMI_CC_SENSOR_INVALID; + return ipmi::responseSensorInvalid(); } - delRecordID = requestData->selRecordID; + delRecordID = selRecordID; } sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; @@ -350,8 +347,7 @@ ipmi_ret_t deleteSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd, catch (const std::runtime_error& e) { log<level::ERR>(e.what()); - *data_len = 0; - return IPMI_CC_UNSPECIFIED_ERROR; + return ipmi::responseUnspecifiedError(); } auto methodCall = bus.new_method_call(service.c_str(), (*iter).c_str(), @@ -359,16 +355,13 @@ ipmi_ret_t deleteSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd, auto reply = bus.call(methodCall); if (reply.is_method_error()) { - *data_len = 0; - return IPMI_CC_UNSPECIFIED_ERROR; + return ipmi::responseUnspecifiedError(); } // Invalidate the cache of dbus entry objects. cache::paths.clear(); - std::memcpy(response, &delRecordID, sizeof(delRecordID)); - *data_len = sizeof(delRecordID); - return IPMI_CC_OK; + return ipmi::responseSuccess(delRecordID); } ipmi_ret_t clearSEL(ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_request_t request, @@ -813,8 +806,9 @@ void register_netfn_storage_functions() getSELEntry, PRIVILEGE_USER); // <Delete SEL Entry> - ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_DELETE_SEL, NULL, - deleteSELEntry, PRIVILEGE_OPERATOR); + ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, + ipmi::storage::cmdDeleteSelEntry, + ipmi::Privilege::Operator, deleteSELEntry); // <Add SEL Entry> ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_ADD_SEL, NULL, |