fan_speed: Always write target prop to sysfs
Leave it up to the fan control application on when to write the fan
target value to the hardware and just always do it instead of throwing
away the write if the previous property value was the same.
This protects against the case when the fan control device resets
itself, such as due to an internal watchdog failure, and sets its
registers to a default that doesn't match sysfs or D-Bus. Now if fan
control writes the target property again, even if it is the same, it
will restore the actual value to what is desired.
Tested:
1. Write directly to sysfs fan*_target to change the value from what is
on D-Bus.
2. Use busctl set-property to set the Target property to the same value
it already is.
3. Ensure the fan*_target file changes back to the value.
Change-Id: Ib71567e08118f1367610ec311a4b990a4e5019c9
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/fan_speed.cpp b/fan_speed.cpp
index 067e882..076807c 100644
--- a/fan_speed.cpp
+++ b/fan_speed.cpp
@@ -18,35 +18,28 @@
uint64_t FanSpeed::target(uint64_t value)
{
- auto curValue = FanSpeedObject::target();
-
- if (curValue != value)
+ try
{
- // Write target out to sysfs
- try
- {
- _ioAccess->write(value, _type, _id, entry::target, hwmonio::retries,
- hwmonio::delay);
- }
- catch (const std::system_error& e)
- {
- using namespace sdbusplus::xyz::openbmc_project::Control::Device::
- Error;
- report<WriteFailure>(
- xyz::openbmc_project::Control::Device::WriteFailure::
- CALLOUT_ERRNO(e.code().value()),
- xyz::openbmc_project::Control::Device::WriteFailure::
- CALLOUT_DEVICE_PATH(_devPath.c_str()));
+ _ioAccess->write(value, _type, _id, entry::target, hwmonio::retries,
+ hwmonio::delay);
+ }
+ catch (const std::system_error& e)
+ {
+ using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error;
+ report<WriteFailure>(
+ xyz::openbmc_project::Control::Device::WriteFailure::CALLOUT_ERRNO(
+ e.code().value()),
+ xyz::openbmc_project::Control::Device::WriteFailure::
+ CALLOUT_DEVICE_PATH(_devPath.c_str()));
- auto file = sysfs::make_sysfs_path(_ioAccess->path(), _type, _id,
- entry::target);
+ auto file = sysfs::make_sysfs_path(_ioAccess->path(), _type, _id,
+ entry::target);
- log<level::INFO>(std::format("Failing sysfs file: {} errno: {}",
- file, e.code().value())
- .c_str());
+ log<level::INFO>(std::format("Failing sysfs file: {} errno: {}", file,
+ e.code().value())
+ .c_str());
- exit(EXIT_FAILURE);
- }
+ exit(EXIT_FAILURE);
}
return FanSpeedObject::target(value);