Skip to content

Commit eefe49b

Browse files
SrideviRameshmanojkiraneda
authored andcommitted
Add API to create fru records only for present frus.
This commit builds the fru records only for the present frus. Any item which is a FRU should by default implement the Inventory.Item Interface and host the present property. So, if the present property is not hosted then FRU is absent. Signed-off-by: Sridevi Ramesh <[email protected]> Change-Id: I5534d6cc1a9f7a1b329975cdd5de54110f456f39
1 parent ab6f9fa commit eefe49b

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

Diff for: common/utils.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace pldm
2222
{
2323
namespace utils
2424
{
25-
2625
constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper";
2726
constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper";
2827
constexpr auto mapperInterface = "xyz.openbmc_project.ObjectMapper";
@@ -581,5 +580,25 @@ std::string getCurrentSystemTime()
581580
return ss.str();
582581
}
583582

583+
bool checkForFruPresence(const std::string& objPath)
584+
{
585+
bool isPresent = false;
586+
static constexpr auto presentInterface =
587+
"xyz.openbmc_project.Inventory.Item";
588+
static constexpr auto presentProperty = "Present";
589+
try
590+
{
591+
auto propVal = pldm::utils::DBusHandler().getDbusPropertyVariant(
592+
objPath.c_str(), presentProperty, presentInterface);
593+
isPresent = std::get<bool>(propVal);
594+
}
595+
catch (const sdbusplus::exception::SdBusError& e)
596+
{
597+
std::cerr << "Failed to check for FRU presence for " << objPath
598+
<< " ERROR =" << e.what() << std::endl;
599+
}
600+
return isPresent;
601+
}
602+
584603
} // namespace utils
585604
} // namespace pldm

Diff for: common/utils.hpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ namespace pldm
2626
{
2727
namespace utils
2828
{
29-
3029
namespace fs = std::filesystem;
3130
using Json = nlohmann::json;
3231
constexpr bool Tx = true;
@@ -150,6 +149,8 @@ using ServiceName = std::string;
150149
using Interfaces = std::vector<std::string>;
151150
using MapperServiceMap = std::vector<std::pair<ServiceName, Interfaces>>;
152151
using GetSubTreeResponse = std::vector<std::pair<ObjectPath, MapperServiceMap>>;
152+
using PropertyMap = std::map<std::string, PropertyValue>;
153+
using InterfaceMap = std::map<std::string, PropertyMap>;
153154

154155
/**
155156
* @brief The interface for DBusHandler
@@ -408,5 +409,12 @@ std::vector<std::string> split(std::string_view srcStr, std::string_view delim,
408409
*/
409410
std::string getCurrentSystemTime();
410411

412+
/** @brief checks if the FRU is actually present.
413+
* @param[in] objPath - FRU object path.
414+
*
415+
* @return bool to indicate presence or absence of FRU.
416+
*/
417+
bool checkForFruPresence(const std::string& objPath);
418+
411419
} // namespace utils
412420
} // namespace pldm

Diff for: libpldmresponder/fru.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515

1616
namespace pldm
1717
{
18-
1918
namespace responder
2019
{
21-
2220
void FruImpl::buildFRUTable()
2321
{
2422
if (isBuilt)
@@ -52,7 +50,13 @@ void FruImpl::buildFRUTable()
5250
for (const auto& object : objects)
5351
{
5452
const auto& interfaces = object.second;
55-
53+
bool isPresent = pldm::utils::checkForFruPresence(object.first.str);
54+
// Do not create fru record if fru is not present.
55+
// Pick up the next available fru.
56+
if (!isPresent)
57+
{
58+
continue;
59+
}
5660
for (const auto& interface : interfaces)
5761
{
5862
if (itemIntfsLookup.find(interface.first) != itemIntfsLookup.end())
@@ -116,7 +120,7 @@ void FruImpl::buildFRUTable()
116120

117121
if (table.size())
118122
{
119-
padBytes = utils::getNumPadBytes(table.size());
123+
padBytes = pldm::utils::getNumPadBytes(table.size());
120124
table.resize(table.size() + padBytes, 0);
121125

122126
// Calculate the checksum
@@ -280,7 +284,7 @@ int FruImpl::getFRURecordByOption(std::vector<uint8_t>& fruData,
280284
return PLDM_FRU_DATA_STRUCTURE_TABLE_UNAVAILABLE;
281285
}
282286

283-
auto pads = utils::getNumPadBytes(recordTableSize);
287+
auto pads = pldm::utils::getNumPadBytes(recordTableSize);
284288
crc32(fruData.data(), recordTableSize + pads);
285289

286290
auto iter = fruData.begin() + recordTableSize + pads;
@@ -293,7 +297,6 @@ int FruImpl::getFRURecordByOption(std::vector<uint8_t>& fruData,
293297

294298
namespace fru
295299
{
296-
297300
Response Handler::getFRURecordTableMetadata(const pldm_msg* request,
298301
size_t /*payloadLength*/)
299302
{

0 commit comments

Comments
 (0)