psu-ng: Continue reading after readFail

Update the PMBus::read() function to allow for not creating journal
trace and elog, but default to continuing to trace and elog, the
previous behavior.

If we reach the limit of read failures that results in a communication
error log, continue to read, but stop logging failures.

If communication restores, we may be able to detect what caused the read
failure, or otherwise detect or clear new faults.

Change-Id: If59b86211ab54c31248ede78f8f117b607298923
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
diff --git a/pmbus.cpp b/pmbus.cpp
index 5483ca4..6ab6944 100644
--- a/pmbus.cpp
+++ b/pmbus.cpp
@@ -174,7 +174,7 @@
     return fs::exists(path);
 }
 
-uint64_t PMBus::read(const std::string& name, Type type)
+uint64_t PMBus::read(const std::string& name, Type type, bool errTrace)
 {
     uint64_t data = 0;
     std::ifstream file;
@@ -192,16 +192,24 @@
     catch (const std::exception& e)
     {
         auto rc = errno;
-        log<level::ERR>((std::string("Failed to read sysfs file "
-                                     "errno=") +
-                         std::to_string(rc) + " FILENAME=" + path.string())
-                            .c_str());
 
-        using metadata = xyz::openbmc_project::Common::Device::ReadFailure;
+        if (errTrace)
+        {
+            log<level::ERR>((std::string("Failed to read sysfs file "
+                                         "errno=") +
+                             std::to_string(rc) + " FILENAME=" + path.string())
+                                .c_str());
 
-        elog<ReadFailure>(
-            metadata::CALLOUT_ERRNO(rc),
-            metadata::CALLOUT_DEVICE_PATH(fs::canonical(basePath).c_str()));
+            using metadata = xyz::openbmc_project::Common::Device::ReadFailure;
+
+            elog<ReadFailure>(
+                metadata::CALLOUT_ERRNO(rc),
+                metadata::CALLOUT_DEVICE_PATH(fs::canonical(basePath).c_str()));
+        }
+        else
+        {
+            throw ReadFailure();
+        }
     }
 
     return data;