Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to libpldm APIs #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Lakshmi-y
Copy link

  • libpldm provides APIs for allocating instance IDs directly, which eliminates the need for remote dbus calls to the pldm daemon. Refactor the code to use these APIs and eliminate all the dbus operations.

  • Replace pldm transport APIs with libpldm pldm_transport APIs to remove the dependency on pldm.

This change removes the dependency on pldm by utilizing the standardized libpldm APIs for transport operations, improving maintainability and compatibility.

We don't currently have the infrastructure in place to get the correct TIDs, so to keep everything working as before use the EID as the TID in the EID-to-TID mapping.

Change-Id: I348d54d9b5db47ef706cf7935e01ab8e7a55a594

@Lakshmi-y Lakshmi-y requested a review from devenrao July 9, 2024 21:02
@Lakshmi-y
Copy link
Author

I created one commit for both instance ID API and transport API changes.
Changes are similar to phosphor-debug-collector, waiting for review,
https://gerrit.openbmc.org/c/openbmc/phosphor-debug-collector/+/72594
https://gerrit.openbmc.org/c/openbmc/phosphor-debug-collector/+/72595

@Lakshmi-y Lakshmi-y force-pushed the libpldm-mctp branch 2 times, most recently from e0f5858 to 74350bc Compare July 10, 2024 04:42
Copy link
Collaborator

@devenrao devenrao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take closer look again after the comments are addressed

Comment on lines +56 to +45
/** @brief Close the PLDM file */
void pldmClose();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate already at line 49

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess Lakshmi fixed this or I don't see what you mean.

int retCode = encode_new_file_req(
pldmInstanceId, pldmDumpType, dumpId, dumpSize,
reinterpret_cast<pldm_msg*>(newFileAvailReqMsg.data()));
if (retCode != PLDM_SUCCESS)
{
freePLDMInstanceID(pldmInstanceId, mctpEndPointId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RAII, enclose pldminstance id and mctp endpoint id in an internal c++ class object and when that goes out of scope it will call freePLDMInstanceID

if (retCode != PLDM_REQUESTER_SUCCESS)
{
freePLDMInstanceID(pldmInstanceId, mctpEndPointId);
pldmClose();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use RAII

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see Andrew Jeffrey's comments on https://gerrit.openbmc.org/c/openbmc/phosphor-debug-collector/+/63889 where he explained that RAII doesn't make sense for the instance IDs

retCode = openPLDM();
if (retCode < 0)
{
freePLDMInstanceID(pldmInstanceId, mctpEndPointId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we call pldmClose here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we call pldmClose here?

No, since the openPLDM call failed.


auto method = bus.new_method_call(objectMapperName, objectMapperPath,
objectMapperName, "GetObject");
void initPLDMInstanceIdDb()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mixing c++ with C functions, why can't we have initPLDMInstanceIdDb, destroyPLDMInstanceIdDb as private methods of the PLDMInstanceManager

Comment on lines +68 to +70
std::this_thread::sleep_for(std::chrono::milliseconds(100));
rc = pldm_instance_id_alloc(pldmInstanceIdDb, tid, &instanceID);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we try only once? or should it be in a loop ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, it is not likely to succeed a second time, so no point retrying.

Comment on lines +109 to +112
elog<NotAllowed>(
Reason("Required host dump action via pldm is not allowed because "
"pldmTransport already setup"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code will throw exception and return from this method, i guess this is not your intention

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is checking to make sure pldmTransport is not set up already, so it is intentional to throw exception here.

"allowed due to pldm_open failed"));
log<level::ERR>(
fmt::format("openPLDM failed, errno({}), FD({})", e, fd).c_str());
elog<NotAllowed>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we use Unavailable here, every where we are using NotAllowed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

"tid to eid mapping, errno={}/{}",
errno, strerror(errno))
.c_str());
pldmClose();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raii

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On what? It doesn't appear that the eid/tid needs to be cleaned up here, but perhaps at a higher level.

int rc = pldm_transport_mctp_demux_init(&mctpDemux);
if (rc)
{
log<level::ERR>(std::format("openMctpDemuxTransport: Failed to init "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we need pldmClose here

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, since pldmClose will clean up mctpDemux, but here that is failed to initialize.

… APIs

Replace the current APIs with libpldm APIs for allocating instance IDs
directly.  This eliminates the need for remote D-Bus calls to the pldm
daemon.

Replace pldm transport APIs with libpldm pldm_transport APIs. This
change migrates the application off the deprecated "requester" APIs in
libpldm. Since we currently lack the infrastructure to obtain the
correct TIDs, use the EID as the TID in the EID-to-TID mapping to
maintain the current functionality.

Change-Id: I348d54d9b5db47ef706cf7935e01ab8e7a55a594
Signed-off-by: Lakshmi Yadlapati <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants