Skip to content

Commit

Permalink
Adding response mechanism to remote terminus
Browse files Browse the repository at this point in the history
- this changes are in suppoort of aynchronous file io operation
between pldm and remote terminus.
- previously pldm send response to remote terminus when it's complete
the operation and that duration pldm is blocked but new response
mechanism will be introduced in case of event loop, pldm can take
time to process request and meanwhile it can receive another request.

Change-Id: I9537d5525e6af76b7867608a2e4f3492b2a631d2
Signed-off-by: Kamalkumar Patel <[email protected]>
  • Loading branch information
Patel-Kamalkumar committed Oct 5, 2023
1 parent b70a72b commit 2bb2365
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 36 deletions.
7 changes: 5 additions & 2 deletions common/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ struct CustomFD
CustomFD(CustomFD&&) = delete;
CustomFD& operator=(CustomFD&&) = delete;

CustomFD(int fd) : fd(fd) {}
CustomFD(int fd, bool closeOnOutScope = true) :
fd(fd), closeOnOutScope(closeOnOutScope)
{}

~CustomFD()
{
if (fd >= 0)
if (fd >= 0 && closeOnOutScope)
{
close(fd);
}
Expand All @@ -78,6 +80,7 @@ struct CustomFD

private:
int fd = -1;
bool closeOnOutScope;
};

/** @brief Calculate the pad for PLDM data
Expand Down
19 changes: 17 additions & 2 deletions oem/ibm/libpldmresponder/file_io.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
#pragma once

#include "common/utils.hpp"
#include "file_io_by_type.hpp"
#include "oem/ibm/requester/dbus_to_file_handler.hpp"
#include "oem_ibm_handler.hpp"
#include "pldmd/handler.hpp"
#include "pldmd/pldm_resp_interface.hpp"
#include "requester/handler.hpp"

#include <fcntl.h>
#include <libpldm/base.h>
#include <libpldm/file_io.h>
#include <libpldm/host.h>
#include <stdint.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include <phosphor-logging/lg2.hpp>

#include <filesystem>
#include <functional>
#include <iostream>
#include <vector>

Expand All @@ -29,6 +33,14 @@ namespace responder
{
namespace dma
{

struct IOPart
{
uint32_t length;
uint32_t offset;
uint64_t address;
};

// The minimum data size of dma transfer in bytes
constexpr uint32_t minSize = 16;

Expand Down Expand Up @@ -172,10 +184,12 @@ class Handler : public CmdHandler
public:
Handler(oem_platform::Handler* oemPlatformHandler, int hostSockFd,
uint8_t hostEid, dbus_api::Requester* dbusImplReqester,
pldm::requester::Handler<pldm::requester::Request>* handler) :
pldm::requester::Handler<pldm::requester::Request>* handler,
pldm::response_api::Transport* respInterface) :
oemPlatformHandler(oemPlatformHandler),
hostSockFd(hostSockFd), hostEid(hostEid),
dbusImplReqester(dbusImplReqester), handler(handler)
dbusImplReqester(dbusImplReqester), handler(handler),
responseHdr({0, 0, respInterface, 0, -1})
{
handlers.emplace(PLDM_READ_FILE_INTO_MEMORY,
[this](const pldm_msg* request, size_t payloadLength) {
Expand Down Expand Up @@ -490,6 +504,7 @@ class Handler : public CmdHandler
pldm::requester::Handler<pldm::requester::Request>* handler;
std::vector<std::unique_ptr<pldm::requester::oem_ibm::DbusToFileHandler>>
dbusToFileHandlers;
ResponseHdr responseHdr;
};

} // namespace oem_ibm
Expand Down
18 changes: 17 additions & 1 deletion oem/ibm/libpldmresponder/file_io_by_type.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
#pragma once

#include "file_io.hpp"
#include "oem_ibm_handler.hpp"
#include "pldmd/pldm_resp_interface.hpp"

namespace pldm
{

namespace responder
{

class FileHandler;
namespace dma
{
class DMA;
} // namespace dma

struct ResponseHdr
{
uint8_t instance_id;
uint8_t command;
pldm::response_api::Transport* respInterface;
std::shared_ptr<FileHandler> functionPtr = nullptr;
int key;
};

namespace fs = std::filesystem;

/**
Expand Down
2 changes: 1 addition & 1 deletion oem/ibm/libpldmresponder/file_io_type_cert.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "file_io_by_type.hpp"
#include "file_io.hpp"

#include <tuple>

Expand Down
2 changes: 1 addition & 1 deletion oem/ibm/libpldmresponder/file_io_type_dump.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "file_io_by_type.hpp"
#include "file_io.hpp"

namespace pldm
{
Expand Down
2 changes: 1 addition & 1 deletion oem/ibm/libpldmresponder/file_io_type_lic.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "file_io_by_type.hpp"
#include "file_io.hpp"

namespace pldm
{
Expand Down
3 changes: 1 addition & 2 deletions oem/ibm/libpldmresponder/file_io_type_lid.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "file_io_by_type.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
#include "file_io.hpp"

#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
Expand Down
2 changes: 1 addition & 1 deletion oem/ibm/libpldmresponder/file_io_type_pcie.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "file_io_by_type.hpp"
#include "file_io.hpp"

#include <arpa/inet.h>
#include <fcntl.h>
Expand Down
2 changes: 1 addition & 1 deletion oem/ibm/libpldmresponder/file_io_type_pel.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "file_io_by_type.hpp"
#include "file_io.hpp"

namespace pldm
{
Expand Down
2 changes: 1 addition & 1 deletion oem/ibm/libpldmresponder/file_io_type_progress_src.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "file_io_by_type.hpp"
#include "file_io.hpp"

namespace pldm
{
Expand Down
2 changes: 1 addition & 1 deletion oem/ibm/libpldmresponder/file_io_type_vpd.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "file_io_by_type.hpp"
#include "file_io.hpp"

namespace pldm
{
Expand Down
1 change: 0 additions & 1 deletion oem/ibm/libpldmresponder/oem_ibm_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include "collect_slot_vpd.hpp"
#include "file_io_type_lid.hpp"
#include "libpldmresponder/file_io.hpp"
#include "libpldmresponder/pdr_utils.hpp"

#include <phosphor-logging/lg2.hpp>
Expand Down
36 changes: 18 additions & 18 deletions oem/ibm/test/libpldmresponder_fileio_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ TEST(ReadFileIntoMemory, BadPath)
// Pass invalid payload length
std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto response = handler.readFileIntoMemory(request, 0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR_INVALID_LENGTH);
Expand Down Expand Up @@ -259,7 +259,7 @@ TEST_F(TestFileTable, ReadFileInvalidFileHandle)

std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto response = handler.readFileIntoMemory(request, requestPayloadLength);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_INVALID_FILE_HANDLE);
Expand Down Expand Up @@ -294,7 +294,7 @@ TEST_F(TestFileTable, ReadFileInvalidOffset)

std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto response = handler.readFileIntoMemory(request, requestPayloadLength);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_DATA_OUT_OF_RANGE);
Expand Down Expand Up @@ -329,7 +329,7 @@ TEST_F(TestFileTable, ReadFileInvalidLength)

std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto response = handler.readFileIntoMemory(request, requestPayloadLength);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR_INVALID_LENGTH);
Expand Down Expand Up @@ -367,7 +367,7 @@ TEST_F(TestFileTable, ReadFileInvalidEffectiveLength)

std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto response = handler.readFileIntoMemory(request, requestPayloadLength);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR_INVALID_LENGTH);
Expand Down Expand Up @@ -399,7 +399,7 @@ TEST(WriteFileFromMemory, BadPath)
// Pass invalid payload length
std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto response = handler.writeFileFromMemory(request, 0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR_INVALID_LENGTH);
Expand Down Expand Up @@ -438,7 +438,7 @@ TEST_F(TestFileTable, WriteFileInvalidFileHandle)

std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto response = handler.writeFileFromMemory(request, requestPayloadLength);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_INVALID_FILE_HANDLE);
Expand Down Expand Up @@ -474,7 +474,7 @@ TEST_F(TestFileTable, WriteFileInvalidOffset)

std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto response = handler.writeFileFromMemory(request, requestPayloadLength);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_DATA_OUT_OF_RANGE);
Expand Down Expand Up @@ -547,7 +547,7 @@ TEST_F(TestFileTable, GetFileTableCommand)

std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto response = handler.getFileTable(requestMsgPtr, requestPayloadLength);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_SUCCESS);
Expand All @@ -574,7 +574,7 @@ TEST_F(TestFileTable, GetFileTableCommandReqLengthMismatch)
// Pass invalid command payload length
std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto response = handler.getFileTable(request, 0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR_INVALID_LENGTH);
Expand All @@ -600,7 +600,7 @@ TEST_F(TestFileTable, GetFileTableCommandOEMAttrTable)

std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto response = handler.getFileTable(requestMsgPtr, requestPayloadLength);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_INVALID_FILE_TABLE_TYPE);
Expand Down Expand Up @@ -632,7 +632,7 @@ TEST_F(TestFileTable, ReadFileBadPath)
// Invalid payload length
std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto response = handler.readFile(requestMsgPtr, 0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR_INVALID_LENGTH);
Expand Down Expand Up @@ -686,7 +686,7 @@ TEST_F(TestFileTable, ReadFileGoodPath)

std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto responseMsg = handler.readFile(requestMsgPtr, payload_length);
auto response = reinterpret_cast<pldm_read_file_resp*>(
responseMsg.data() + sizeof(pldm_msg_hdr));
Expand Down Expand Up @@ -740,7 +740,7 @@ TEST_F(TestFileTable, WriteFileBadPath)
// Invalid payload length
std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto response = handler.writeFile(requestMsgPtr, 0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR_INVALID_LENGTH);
Expand Down Expand Up @@ -791,7 +791,7 @@ TEST_F(TestFileTable, WriteFileGoodPath)

std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto responseMsg = handler.writeFile(requestMsgPtr, payload_length);
auto response = reinterpret_cast<pldm_read_file_resp*>(
responseMsg.data() + sizeof(pldm_msg_hdr));
Expand Down Expand Up @@ -829,7 +829,7 @@ TEST(writeFileByTypeFromMemory, testBadPath)

std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto response = handler.writeFileByTypeFromMemory(req, 0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());

Expand Down Expand Up @@ -909,7 +909,7 @@ TEST(readFileByTypeIntoMemory, testBadPath)

std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto response = handler.readFileByTypeIntoMemory(req, 0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
struct pldm_read_write_file_by_type_memory_resp* resp =
Expand Down Expand Up @@ -951,7 +951,7 @@ TEST(readFileByType, testBadPath)

std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
oem_ibm::Handler handler(oemPlatformHandler.get(), hostSocketFd, host_eid,
nullptr, nullptr);
nullptr, nullptr, nullptr);
auto response = handler.readFileByType(req, 0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
struct pldm_read_write_file_by_type_resp* resp =
Expand Down
Loading

0 comments on commit 2bb2365

Please sign in to comment.