Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/persistent_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <boost/beast/http/fields.hpp>
#include <nlohmann/json.hpp>

#include <unistd.h>

#include <chrono>
#include <cstdint>
#include <filesystem>
Expand Down Expand Up @@ -359,7 +361,17 @@ class ConfigFile
if (ec)
{
BMCWEB_LOG_ERROR("Failed to write file {}", ec.message());
return;
}

// Ensure session data reaches durable storage before BMC reboot can
// tear down the process or reset the platform.
if (::fsync(persistentFile.native_handle()) != 0)
{
BMCWEB_LOG_ERROR("Failed to fsync persistent data");
return;
}
SessionStore::getInstance().clearNeedWrite();
}

std::string systemUuid;
Expand Down
6 changes: 6 additions & 0 deletions include/sessions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ class SessionStore
{
return needWrite;
}

void clearNeedWrite()
{
needWrite = false;
}

int64_t getTimeoutInSeconds() const
{
return std::chrono::seconds(timeoutInSeconds).count();
Expand Down
14 changes: 14 additions & 0 deletions redfish-core/lib/managers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ inline std::string getBMCUpdateServicePath()
return "/xyz/openbmc_project/software";
}

inline void flushPersistentSessions()
{
persistent_data::SessionStore::getInstance().applySessionTimeouts();
if (persistent_data::SessionStore::getInstance().needsWrite())
{
persistent_data::getConfig().writeData();
}
}

/**
* Function reboots the BMC.
*
Expand All @@ -82,6 +91,9 @@ inline std::string getBMCUpdateServicePath()
inline void doBMCGracefulRestart(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
// Persist sessions before reboot so web UI login survives BMC reset.
flushPersistentSessions();

const char* processName = "xyz.openbmc_project.State.BMC";
const char* objectPath = "/xyz/openbmc_project/state/bmc0";
const char* interfaceName = "xyz.openbmc_project.State.BMC";
Expand Down Expand Up @@ -109,6 +121,8 @@ inline void doBMCGracefulRestart(
inline void doBMCForceRestart(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
flushPersistentSessions();

const char* processName = "xyz.openbmc_project.State.BMC";
const char* objectPath = "/xyz/openbmc_project/state/bmc0";
const char* interfaceName = "xyz.openbmc_project.State.BMC";
Expand Down