Post commit readiness latch to smbios grpc Port downstream patch https://gbmc-private-review.git.corp.google.com/c/meta-fii-google/+/97105 to shared code PiperOrigin-RevId: 969568786 Change-Id: I0f97ad883f14a4180182e31b741d0e1d100e09fb
diff --git a/src/smbios_callback.cc b/src/smbios_callback.cc index a23c9b3..88ff115 100644 --- a/src/smbios_callback.cc +++ b/src/smbios_callback.cc
@@ -7,11 +7,14 @@ #include <cerrno> #include <cstring> +#include <system_error> // NOLINT +#include <filesystem> // NOLINT #include <fstream> #include <string> #include <utility> #include "absl/log/log.h" +#include "absl/strings/str_cat.h" #include "smbios_file.h" #include "grpcpp/server_context.h" #include "grpcpp/support/status.h" @@ -99,12 +102,50 @@ LOG(ERROR) << "Could not save SMBIOS to file: " << fileName; return; } - LOG(INFO) << "smbos file saved " << fileName; + LOG(INFO) << "smbios file saved " << fileName; + + writeStatusLatch(); } sendSignalToSmbiosApp(); } +void SmbiosTransferServiceImpl::writeStatusLatch() { + std::string finalStatusFilePath = absl::StrCat( + basePath_, "/run/smbios-mdr/status-host-", std::to_string(instance + 1)); + std::string tempStatusFilePath = finalStatusFilePath + ".tmp"; + + std::filesystem::path statusDir = + std::filesystem::path(finalStatusFilePath).parent_path(); + std::error_code ec; + std::filesystem::create_directories(statusDir, ec); + if (ec) { + LOG(ERROR) << "Unable to make directory " << statusDir + << ": " << ec.message(); + return; + } + + std::ofstream tempFile(tempStatusFilePath); + if (!tempFile.is_open()) { + LOG(ERROR) << "Unable to open temporary status file for writing: " + << tempStatusFilePath; + return; + } + + tempFile << "NEW"; + tempFile.close(); + + std::filesystem::rename(tempStatusFilePath, finalStatusFilePath, ec); + if (ec) { + LOG(ERROR) << "Failed to atomically rename status file from " + << tempStatusFilePath << " to " << finalStatusFilePath + << ": " << ec.message(); + return; + } + + LOG(INFO) << "Status file successfully written to " << finalStatusFilePath; +} + void SmbiosTransferServiceImpl::sendSignalToSmbiosApp() { LOG(INFO) << "Attempting to send Signal to smbiosmdrv2app for instance " << instance;
diff --git a/src/smbios_callback.h b/src/smbios_callback.h index 6e083bc..04d2be0 100644 --- a/src/smbios_callback.h +++ b/src/smbios_callback.h
@@ -32,6 +32,7 @@ protected: [[nodiscard]] bool claimLinkBusy(); void writeThenStart(const SmbiosEntry& entry, bool isWrite); + void writeStatusLatch(); void sendSignalToSmbiosApp(); private: