From 2ecf51204690d99477352188e2b83def7a7c1f1a Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Fri, 27 Apr 2018 14:31:51 -0700 Subject: watchdog: Get only the initialized property during reset Since we switched to resetting the watchdog with a built-in method, we are only using a single property from the watchdog. Instead of fetching all the properties and reading just the initialized one, only request the initialized property from the watchdog. Change-Id: I5e29b5100629e1ce23f352b0b749a434cd1ab793 Signed-off-by: William A. Kennington III --- app/watchdog.cpp | 3 +-- app/watchdog_service.cpp | 29 +++++++++++++++++++++++++++++ app/watchdog_service.hpp | 17 ++++++++++++++++- 3 files changed, 46 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/watchdog.cpp b/app/watchdog.cpp index dbd7426..da8ccf3 100644 --- a/app/watchdog.cpp +++ b/app/watchdog.cpp @@ -31,11 +31,10 @@ ipmi_ret_t ipmi_app_watchdog_reset( try { WatchdogService wd_service; - WatchdogService::Properties wd_prop = wd_service.getProperties(); // Notify the caller if we haven't initialized our timer yet // so it can configure actions and timeouts - if (!wd_prop.initialized) + if (!wd_service.getInitialized()) { return IPMI_WDOG_CC_NOT_INIT; } diff --git a/app/watchdog_service.cpp b/app/watchdog_service.cpp index 26962dc..898cf77 100644 --- a/app/watchdog_service.cpp +++ b/app/watchdog_service.cpp @@ -84,6 +84,30 @@ WatchdogService::Properties WatchdogService::getProperties() return wd_prop; } +template +T WatchdogService::getProperty(const std::string& key) +{ + bool wasValid = wd_service.isValid(bus); + auto request = wd_service.newMethodCall(bus, prop_intf, "Get"); + request.append(wd_intf, key); + auto response = bus.call(request); + if (response.is_method_error()) + { + wd_service.invalidate(); + if (wasValid) + { + // Retry the request once in case the cached service was stale + return getProperty(key); + } + log("WatchdogService: Method error getting property", + entry("PROPERTY=%s", key.c_str())); + elog(); + } + variant value; + response.read(value); + return get(value); +} + template void WatchdogService::setProperty(const std::string& key, const T& val) { @@ -105,6 +129,11 @@ void WatchdogService::setProperty(const std::string& key, const T& val) } } +bool WatchdogService::getInitialized() +{ + return getProperty("Initialized"); +} + void WatchdogService::setInitialized(bool initialized) { setProperty("Initialized", initialized); diff --git a/app/watchdog_service.hpp b/app/watchdog_service.hpp index ad92213..dfc913a 100644 --- a/app/watchdog_service.hpp +++ b/app/watchdog_service.hpp @@ -41,8 +41,15 @@ class WatchdogService { */ Properties getProperties(); + /** @brief Get the value of the initialized property on the host + * watchdog + * + * @return The value of the property + */ + bool getInitialized(); + /** @brief Sets the value of the initialized property on the host - * watchdog + * watchdog * * @param[in] initialized - The new initializedvalue */ @@ -79,6 +86,14 @@ class WatchdogService { /** @brief The name of the mapped host watchdog service */ static ipmi::ServiceCache wd_service; + /** @brief Gets the value of the property on the host watchdog + * + * @param[in] key - The name of the property + * @return The value of the property + */ + template + T getProperty(const std::string& key); + /** @brief Sets the value of the property on the host watchdog * * @param[in] key - The name of the property -- cgit v1.2.1