summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rw-r--r--discover_system_state.cpp78
-rw-r--r--host_state_manager.cpp68
-rw-r--r--host_state_manager.hpp62
-rw-r--r--host_state_serialize.cpp68
-rw-r--r--host_state_serialize.hpp37
6 files changed, 125 insertions, 189 deletions
diff --git a/Makefile.am b/Makefile.am
index a0d5d10..06b7331 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -10,7 +10,6 @@ sbin_PROGRAMS = \
phosphor_host_state_manager_SOURCES = \
host_state_manager.cpp \
host_state_manager_main.cpp \
- host_state_serialize.cpp \
settings.cpp
phosphor_chassis_state_manager_SOURCES = \
diff --git a/discover_system_state.cpp b/discover_system_state.cpp
index c055f9f..303b4a4 100644
--- a/discover_system_state.cpp
+++ b/discover_system_state.cpp
@@ -6,7 +6,6 @@
#include <sdbusplus/server.hpp>
#include <phosphor-logging/log.hpp>
#include <phosphor-logging/elog-errors.hpp>
-#include "chassis_state_manager.hpp"
#include "host_state_manager.hpp"
#include "settings.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
@@ -31,8 +30,6 @@ constexpr auto PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties";
constexpr auto HOST_PATH = "/xyz/openbmc_project/state/host0";
-constexpr auto CHASSIS_PATH = "/xyz/openbmc_project/state/chassis0";
-
std::string getService(sdbusplus::bus::bus& bus, std::string path,
std::string interface)
{
@@ -131,43 +128,50 @@ int main()
using namespace phosphor::state::manager;
namespace server = sdbusplus::xyz::openbmc_project::State::server;
- std::string currentPowerState = getProperty(bus, CHASSIS_PATH,
- CHASSIS_BUSNAME,
- "CurrentPowerState");
+ // This application is only run if chassis power is off
- if(currentPowerState == convertForMessage(server::Chassis::PowerState::Off))
+ auto method =
+ bus.new_method_call(
+ settings.service(settings.powerRestorePolicy,
+ powerRestoreIntf).c_str(),
+ settings.powerRestorePolicy.c_str(),
+ "org.freedesktop.DBus.Properties",
+ "Get");
+ method.append(powerRestoreIntf, "PowerRestorePolicy");
+ auto reply = bus.call(method);
+ if (reply.is_method_error())
{
- auto method =
- bus.new_method_call(
- settings.service(settings.powerRestorePolicy,
- powerRestoreIntf).c_str(),
- settings.powerRestorePolicy.c_str(),
- "org.freedesktop.DBus.Properties",
- "Get");
- method.append(powerRestoreIntf, "PowerRestorePolicy");
- auto reply = bus.call(method);
- if (reply.is_method_error())
- {
- log<level::ERR>("Error in PowerRestorePolicy Get");
- elog<InternalFailure>();
- }
-
- sdbusplus::message::variant<std::string> result;
- reply.read(result);
- auto powerPolicy = result.get<std::string>();
-
- log<level::INFO>("Host power is off, checking power policy",
- entry("POWER_POLICY=%s", powerPolicy.c_str()));
-
- if (RestorePolicy::Policy::AlwaysOn ==
- RestorePolicy::convertPolicyFromString(powerPolicy))
- {
- log<level::INFO>("power_policy=ALWAYS_POWER_ON, powering host on");
- setProperty(bus, HOST_PATH, HOST_BUSNAME,
- "RequestedHostTransition",
- convertForMessage(server::Host::Transition::On));
- }
+ log<level::ERR>("Error in PowerRestorePolicy Get");
+ elog<InternalFailure>();
+ }
+
+ sdbusplus::message::variant<std::string> result;
+ reply.read(result);
+ auto powerPolicy = result.get<std::string>();
+ log<level::INFO>("Host power is off, checking power policy",
+ entry("POWER_POLICY=%s", powerPolicy.c_str()));
+
+ if (RestorePolicy::Policy::AlwaysOn ==
+ RestorePolicy::convertPolicyFromString(powerPolicy))
+ {
+ log<level::INFO>("power_policy=ALWAYS_POWER_ON, powering host on");
+ setProperty(bus, HOST_PATH, HOST_BUSNAME,
+ "RequestedHostTransition",
+ convertForMessage(server::Host::Transition::On));
+ }
+ else if(RestorePolicy::Policy::Restore ==
+ RestorePolicy::convertPolicyFromString(powerPolicy))
+ {
+ log<level::INFO>("power_policy=RESTORE, restoring last state");
+
+ // Read last requested state and re-request it to execute it
+ auto hostReqState = getProperty(bus, HOST_PATH,
+ HOST_BUSNAME,
+ "RequestedHostTransition");
+ setProperty(bus, HOST_PATH, HOST_BUSNAME,
+ "RequestedHostTransition",
+ hostReqState);
}
return 0;
diff --git a/host_state_manager.cpp b/host_state_manager.cpp
index 6b13276..0991cf7 100644
--- a/host_state_manager.cpp
+++ b/host_state_manager.cpp
@@ -2,14 +2,18 @@
#include <map>
#include <string>
#include <systemd/sd-bus.h>
+#include <cereal/cereal.hpp>
+#include <cereal/types/string.hpp>
+#include <cereal/types/vector.hpp>
+#include <cereal/types/tuple.hpp>
+#include <cereal/archives/json.hpp>
+#include <fstream>
#include <sdbusplus/server.hpp>
#include <phosphor-logging/log.hpp>
#include <phosphor-logging/elog-errors.hpp>
-#include <experimental/filesystem>
#include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include "host_state_manager.hpp"
-#include "host_state_serialize.hpp"
#include "config.h"
@@ -98,9 +102,7 @@ void Host::determineInitialState()
server::Host::requestedHostTransition(Transition::Off);
}
- auto restore = getStateRestoreSetting();
-
- if ((!restore) || (!deserialize(HOST_STATE_PERSIST_PATH, *this)))
+ if (!deserialize(HOST_STATE_PERSIST_PATH))
{
//set to default value.
server::Host::requestedHostTransition(Transition::Off);
@@ -109,40 +111,6 @@ void Host::determineInitialState()
return;
}
-bool Host::getStateRestoreSetting() const
-{
- using namespace settings;
- using namespace sdbusplus::xyz::openbmc_project::Common::Error;
- using namespace sdbusplus::xyz::openbmc_project::Control::Power::server;
-
- auto method =
- bus.new_method_call(
- settings.service(settings.powerRestorePolicy,
- powerRestoreIntf).c_str(),
- settings.powerRestorePolicy.c_str(),
- "org.freedesktop.DBus.Properties",
- "Get");
-
- method.append(powerRestoreIntf, "PowerRestorePolicy");
- auto reply = bus.call(method);
- if (reply.is_method_error())
- {
- log<level::ERR>("Error in PowerRestorePolicy Get");
- elog<InternalFailure>();
- }
-
- sdbusplus::message::variant<std::string> result;
- reply.read(result);
- auto powerPolicy = result.get<std::string>();
-
- if (RestorePolicy::Policy::Restore ==
- RestorePolicy::convertPolicyFromString(powerPolicy))
- {
- return true;
- }
- return false;
-}
-
void Host::executeTransition(Transition tranReq)
{
auto sysdUnit = SYSTEMD_TARGET_TABLE.find(tranReq)->second;
@@ -319,6 +287,26 @@ uint32_t Host::decrementRebootCount()
return rebootCount;
}
+fs::path Host::serialize(const fs::path& dir)
+{
+ std::ofstream os(dir.c_str(), std::ios::binary);
+ cereal::JSONOutputArchive oarchive(os);
+ oarchive(*this);
+ return dir;
+}
+
+bool Host::deserialize(const fs::path& path)
+{
+ if (fs::exists(path))
+ {
+ std::ifstream is(path.c_str(), std::ios::in | std::ios::binary);
+ cereal::JSONInputArchive iarchive(is);
+ iarchive(*this);
+ return true;
+ }
+ return false;
+}
+
Host::Transition Host::requestedHostTransition(Transition value)
{
log<level::INFO>(
@@ -339,7 +327,7 @@ Host::Transition Host::requestedHostTransition(Transition value)
executeTransition(value);
auto retVal = server::Host::requestedHostTransition(value);
- serialize(*this);
+ serialize();
return retVal;
}
diff --git a/host_state_manager.hpp b/host_state_manager.hpp
index af748f5..a0ba768 100644
--- a/host_state_manager.hpp
+++ b/host_state_manager.hpp
@@ -2,6 +2,8 @@
#include <string>
#include <functional>
+#include <experimental/filesystem>
+#include <cereal/access.hpp>
#include <sdbusplus/bus.hpp>
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/State/Boot/Progress/server.hpp>
@@ -27,6 +29,7 @@ using HostInherit = sdbusplus::server::object::object<
using namespace phosphor::logging;
namespace sdbusRule = sdbusplus::bus::match::rules;
+namespace fs = std::experimental::filesystem;
/** @class Host
* @brief OpenBMC host state management implementation.
@@ -157,12 +160,6 @@ class Host : public HostInherit
*/
void sysStateChange(sdbusplus::message::message& msg);
- /** @brief Determine whether restoring of host requested state is enabled
- *
- * @return boolean corresponding to restore setting
- */
- bool getStateRestoreSetting() const;
-
/** @brief Decrement reboot count
*
* This is used internally to this application to decrement the boot
@@ -173,6 +170,59 @@ class Host : public HostInherit
*/
uint32_t decrementRebootCount();
+ // Allow cereal class access to allow these next two function to be
+ // private
+ friend class cereal::access;
+
+ /** @brief Function required by Cereal to perform serialization.
+ *
+ * @tparam Archive - Cereal archive type (binary in our case).
+ * @param[in] archive - reference to Cereal archive.
+ */
+ template<class Archive>
+ void save(Archive& archive) const
+ {
+ archive(convertForMessage(sdbusplus::xyz::openbmc_project::
+ State::server::Host::
+ requestedHostTransition()));
+ }
+
+ /** @brief Function required by Cereal to perform deserialization.
+ *
+ * @tparam Archive - Cereal archive type (binary in our case).
+ * @param[in] archive - reference to Cereal archive.
+ */
+ template<class Archive>
+ void load(Archive& archive)
+ {
+ std::string str;
+ archive(str);
+ auto reqTran = Host::convertTransitionFromString(str);
+ // When restoring, set the requested state with persistent value
+ // but don't call the override which would execute it
+ sdbusplus::xyz::openbmc_project::State::server::Host::
+ requestedHostTransition(reqTran);
+ }
+
+ /** @brief Serialize and persist requested host state
+ *
+ * @param[in] dir - pathname of file where the serialized host state will
+ * be placed.
+ *
+ * @return fs::path - pathname of persisted requested host state.
+ */
+ fs::path serialize(const fs::path& dir =
+ fs::path(HOST_STATE_PERSIST_PATH));
+
+ /** @brief Deserialze a persisted requested host state.
+ *
+ * @param[in] path - pathname of persisted host state file
+ *
+ * @return bool - true if the deserialization was successful, false
+ * otherwise.
+ */
+ bool deserialize(const fs::path& path);
+
/** @brief Persistent sdbusplus DBus bus connection. */
sdbusplus::bus::bus& bus;
diff --git a/host_state_serialize.cpp b/host_state_serialize.cpp
deleted file mode 100644
index d5a3a98..0000000
--- a/host_state_serialize.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-#include <cereal/types/string.hpp>
-#include <cereal/types/vector.hpp>
-#include <cereal/types/tuple.hpp>
-#include <cereal/archives/json.hpp>
-#include <fstream>
-#include "host_state_serialize.hpp"
-#include "host_state_manager.hpp"
-
-namespace phosphor
-{
-namespace state
-{
-namespace manager
-{
-/** @brief Function required by Cereal to perform serialization.
- * @tparam Archive - Cereal archive type (binary in our case).
- * @param[in] archive - reference to Cereal archive.
- * @param[in] host - const reference to host.
- */
-template<class Archive>
-void save(Archive& archive, const Host& host)
-{
- archive(convertForMessage(host.sdbusplus::xyz::openbmc_project::
- State::server::Host::requestedHostTransition()));
-}
-
-/** @brief Function required by Cereal to perform deserialization.
- * @tparam Archive - Cereal archive type (binary in our case).
- * @param[in] archive - reference to Cereal archive.
- * @param[in] host - reference to host.
- */
-template<class Archive>
-void load(Archive& archive, Host& host)
-{
- using namespace
- sdbusplus::xyz::openbmc_project::State::server;
-
- Host::Transition requestedHostTransition{};
-
- std::string str;
- archive(str);
- requestedHostTransition = Host::convertTransitionFromString(
- str);
- host.requestedHostTransition(requestedHostTransition);
-}
-
-fs::path serialize(const Host& host, const fs::path& dir)
-{
- std::ofstream os(dir.c_str(), std::ios::binary);
- cereal::JSONOutputArchive oarchive(os);
- oarchive(host);
- return dir;
-}
-
-bool deserialize(const fs::path& path, Host& host)
-{
- if (fs::exists(path))
- {
- std::ifstream is(path.c_str(), std::ios::in | std::ios::binary);
- cereal::JSONInputArchive iarchive(is);
- iarchive(host);
- return true;
- }
- return false;
-}
-} //namespace manager
-} // namespace state
-} // namespace phosphor
diff --git a/host_state_serialize.hpp b/host_state_serialize.hpp
deleted file mode 100644
index 0bc7684..0000000
--- a/host_state_serialize.hpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#pragma once
-
-#include <string>
-#include <vector>
-#include <experimental/filesystem>
-#include "host_state_manager.hpp"
-#include "config.h"
-
-namespace phosphor
-{
-namespace state
-{
-namespace manager
-{
-
-namespace fs = std::experimental::filesystem;
-
-/** @brief Serialize and persist requested host state
- * @param[in] host - const reference to host state.
- * @param[in] dir - pathname of file where the serialized host state will
- * be placed.
- * @return fs::path - pathname of persisted requested host state.
- */
-fs::path serialize(const Host& host,
- const fs::path& dir = fs::path(HOST_STATE_PERSIST_PATH));
-
-/** @brief Deserialze a persisted requested host state.
- * @param[in] path - pathname of persisted host state file
- * @param[in] host - reference to host state object which is the target of
- * deserialization.
- * @return bool - true if the deserialization was successful, false otherwise.
- */
-bool deserialize(const fs::path& path, Host& host);
-
-} // namespace manager
-} // namespace state
-} // namespace phosphor
OpenPOWER on IntegriCloud