From c51afd54a55d5c8d6cb6e9583e209788f7996fe3 Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Thu, 7 Mar 2024 10:13:14 -0800 Subject: Call systemd SetTime directly Internally inside phosphor-time-manager, the elapsed(uint64) dbus call just forwards the request directly to systemd after static casting to int64_t (signed). bmcweb should just call systemd directly, for several reasons. phosphor-timesyncd might block on other calls, given it's a single threaded blocking design, due to bugs like #264. Calling systemd directly means that calls that don't require phosphor networkd won't be blocked. Calling systemd directly allows bmcweb to drop some code that parses a date as int64_t, then converts it to uint64_t to fulfill the phosphor datetime interface. We can now keep int64_t all the way through. Calling systemd directly allows bmcweb to give a more specific error code in the case there NTP is enabled, registering a PropertyValueConflict error, instead of a 500 InternalError. Tested: Patching DateTime property with NTP enabled returns 400, PropertyValueConflict ``` curl -vvvv -k --user "root:0penBmc" -H "Content-Type: application/json" -X PATCH -d '{"DateTime":"2020-12-15T15:40:52+00:00"}' https://192.168.7.2/redfish/v1/Managers/bmc ``` Disabling NTP using the following command: ``` curl -vvvv -k --user "root:0penBmc" -H "Content-Type: application/json" -X PATCH -d '{"NTP":{"ProtocolEnabled":false}}' https://192.168.7.2/redfish/v1/Managers/bmc/NetworkProtocol ``` Allows the prior command to succeed. [1] https://github.com/openbmc/phosphor-time-manager/blob/5ce9ac0e56440312997b25771507585905e8b360/bmc_epoch.cpp#L126 Change-Id: I6fbb6f63e17de8ab847ca5ed4eadc2bd313586d2 Signed-off-by: Ed Tanous --- redfish-core/src/utils/time_utils.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'redfish-core/src/utils') diff --git a/redfish-core/src/utils/time_utils.cpp b/redfish-core/src/utils/time_utils.cpp index f427ba64c4..3aa3e79b54 100644 --- a/redfish-core/src/utils/time_utils.cpp +++ b/redfish-core/src/utils/time_utils.cpp @@ -12,13 +12,13 @@ namespace redfish::time_utils { -using usSinceEpoch = std::chrono::duration; + std::optional dateStringToEpoch(std::string_view datetime) { for (const char* format : std::to_array({"%FT%T%Ez", "%FT%TZ", "%FT%T"})) { // Parse using signed so we can detect negative dates - std::chrono::sys_time> date; + std::chrono::sys_time date; std::istringstream iss(std::string{datetime}); #if __cpp_lib_chrono >= 201907L namespace chrono_from_stream = std::chrono; @@ -36,7 +36,7 @@ std::optional dateStringToEpoch(std::string_view datetime) // More information left at end of string. continue; } - return usSinceEpoch{date.time_since_epoch().count()}; + return date.time_since_epoch(); } } return std::nullopt; -- cgit v1.2.3