summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2017-11-07 12:09:49 -0800
committerPatrick Venture <venture@google.com>2018-03-30 14:44:06 +0000
commitc1cece76a0d0054b705a7f05c8500fecdfb8c5e8 (patch)
treefede075880e005c2b9c13e9d2397162107699f75
parenta23babd6952cb21397d6aa408a827047d1de81de (diff)
downloadphosphor-hwmon-c1cece76a0d0054b705a7f05c8500fecdfb8c5e8.tar.gz
phosphor-hwmon-c1cece76a0d0054b705a7f05c8500fecdfb8c5e8.zip
Add configure option for how read fails behave
Different platforms have different requirements for handling hwmon sysfs access failures. The default behavior is that a read failure leads to the daemon exiting after some number of read failures. This can be controlled to then remove the object from the dbus on failure. Now, it can instead be controlled to return -errno on read failure. This new behavior to set the value to -errno must be checked by whatever mechanism is reporting the value. Change-Id: I50b93aea56f22267da79c9571319f281e24a1e6f Signed-off-by: Patrick Venture <venture@google.com>
-rw-r--r--configure.ac14
-rw-r--r--mainloop.cpp10
-rw-r--r--sysfs.cpp4
3 files changed, 28 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 7c516f8..0878173 100644
--- a/configure.ac
+++ b/configure.ac
@@ -50,6 +50,7 @@ AS_IF([test "x$enable_oe_sdk" == "xyes"],
AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
)
+# When a sensor access fails, just remove the sensor from dbus instead of exiting the daemon.
AC_ARG_ENABLE([remove-from-dbus-on-fail],
AS_HELP_STRING([--enable-remove-from-dbus-on-fail], [Remove properties from D-Bus on access failures])
)
@@ -61,6 +62,19 @@ AS_IF([test "x$enable_remove_from_dbus_on_fail" == "xyes"],
AC_DEFINE_UNQUOTED([REMOVE_ON_FAIL], ["$REMOVE_ON_FAIL"], [Remove properties from D-Bus on access failures])
)
+# When a sensor read fails, set the Value on dbus with -errno.
+# Incompatible with remove-from-dbus-on-fail.
+AC_ARG_ENABLE([negative-errno-on-fail],
+ AS_HELP_STRING([--enable-negative-errno-on-fail], [Set sensor value to -errno on read failures])
+)
+
+AC_ARG_VAR(NEGATIVE_ERRNO_ON_FAIL, [Set sensor value to -errno on read failures])
+
+AS_IF([test "x$enable_negative_errno_on_fail" == "xyes"],
+ [NEGATIVE_ERRNO_ON_FAIL="yes"]
+ AC_DEFINE_UNQUOTED([NEGATIVE_ERRNO_ON_FAIL], ["$NEGATIVE_ERRNO_ON_FAIL"], [Set sensor value to -errno on read failures])
+)
+
AC_ARG_VAR(BUSNAME_PREFIX, [The DBus busname prefix.])
AC_ARG_VAR(SENSOR_ROOT, [The DBus sensors namespace root.])
AS_IF([test "x$BUSNAME_PREFIX" == "x"], [BUSNAME_PREFIX="xyz.openbmc_project.Hwmon"])
diff --git a/mainloop.cpp b/mainloop.cpp
index cfa5483..dfba15f 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -157,6 +157,16 @@ auto getAttributes(const std::string& type, Attributes& attributes)
int64_t adjustValue(const SensorSet::key_type& sensor, int64_t value)
{
+// Because read doesn't have an out pointer to store errors.
+// let's assume negative values are errors if they have this
+// set.
+#ifdef NEGATIVE_ERRNO_ON_FAIL
+ if (value < 0)
+ {
+ return value;
+ }
+#endif
+
const auto& it = sensorAdjusts.find(sensor);
if (it != sensorAdjusts.end())
{
diff --git a/sysfs.cpp b/sysfs.cpp
index f348be4..5c7dbee 100644
--- a/sysfs.cpp
+++ b/sysfs.cpp
@@ -21,6 +21,7 @@
#include <memory>
#include <phosphor-logging/log.hpp>
#include <thread>
+#include "config.h"
#include "sysfs.hpp"
using namespace std::string_literals;
@@ -361,6 +362,9 @@ int64_t HwmonIO::read(
!retries)
{
// Not a retryable error or out of retries.
+#ifdef NEGATIVE_ERRNO_ON_FAIL
+ return -rc;
+#endif
// Work around GCC bugs 53984 and 66145 for callers by
// explicitly raising system_error here.
OpenPOWER on IntegriCloud