Revert clearing PDRs if host power is off
Code was added to clear the PDRs when the host was powered off, but the
next power on occ-control never saw the OCC StateSensor updates.
This change will be reverted to resolve this issue.
Tested on multiple machines with multiple reboots and guarded procs
Change-Id: Ibea28ede25c81f22e4e9fe2574c1668c4a81352c
Signed-off-by: Chris Cain <cjcain@us.ibm.com>
diff --git a/pldm.cpp b/pldm.cpp
index 1ce23f4..470312c 100644
--- a/pldm.cpp
+++ b/pldm.cpp
@@ -131,12 +131,6 @@
void Interface::sensorEvent(sdbusplus::message::message& msg)
{
- if (!open_power::occ::utils::isHostRunning())
- {
- clearData();
- return;
- }
-
if (!isOCCSensorCacheValid())
{
fetchSensorInfo(PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
@@ -243,6 +237,23 @@
}
}
+void Interface::hostStateEvent(sdbusplus::message::message& msg)
+{
+ std::map<std::string, std::variant<std::string>> properties{};
+ std::string interface;
+ msg.read(interface, properties);
+ const auto stateEntry = properties.find("CurrentHostState");
+ if (stateEntry != properties.end())
+ {
+ auto stateEntryValue = stateEntry->second;
+ auto propVal = std::get<std::string>(stateEntryValue);
+ if (propVal == "xyz.openbmc_project.State.Host.HostState.Off")
+ {
+ clearData();
+ }
+ }
+}
+
void Interface::clearData()
{
if (!sensorToOCCInstance.empty())
@@ -874,8 +885,6 @@
"checkActiveSensor: Unable to find PLDM sensor for OCC{}",
instance)
.c_str());
- // Clear cache to recollect the sensor ids
- clearData();
}
}
diff --git a/pldm.hpp b/pldm.hpp
index f67a36b..3f0c844 100644
--- a/pldm.hpp
+++ b/pldm.hpp
@@ -70,6 +70,12 @@
MatchRules::interface("xyz.openbmc_project.PLDM.Event"),
std::bind(std::mem_fn(&Interface::sensorEvent), this,
std::placeholders::_1)),
+ hostStateSignal(
+ open_power::occ::utils::getBus(),
+ MatchRules::propertiesChanged("/xyz/openbmc_project/state/host0",
+ "xyz.openbmc_project.State.Host"),
+ std::bind(std::mem_fn(&Interface::hostStateEvent), this,
+ std::placeholders::_1)),
sdpEvent(sdeventplus::Event::get_default()),
pldmRspTimer(
sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>(
@@ -168,6 +174,9 @@
*/
sdbusplus::bus::match_t pldmEventSignal;
+ /** @brief Used to subscribe for host state change signal */
+ sdbusplus::bus::match_t hostStateSignal;
+
/** @brief PLDM Sensor ID to OCC Instance mapping
*/
SensorToInstance sensorToOCCInstance;
@@ -250,6 +259,14 @@
*/
void sensorEvent(sdbusplus::message::message& msg);
+ /** @brief When the host state changes and if the CurrentHostState is
+ * xyz.openbmc_project.State.Host.HostState.Off then
+ * the cache of OCC sensors and effecters mapping is cleared.
+ *
+ * @param[in] msg - data associated with the subscribed signal
+ */
+ void hostStateEvent(sdbusplus::message::message& msg);
+
/** @brief Called when it is determined that the Host is not running.
* The cache of OCC sensors and effecters mapping is cleared.
*/