summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdriana Kobylak <anoo@us.ibm.com>2018-02-27 15:36:59 -0600
committerAdriana Kobylak <anoo@us.ibm.com>2018-03-02 09:51:17 -0600
commit2285fe0fc6a6bba7c587bec0a1f733b333dc2650 (patch)
tree66a38d166d39d50a5f635a18fe3a69ed29cbf909
parent83cd21fbab1a59f57c4a8752406478a0127bde21 (diff)
downloadphosphor-bmc-code-mgmt-2285fe0fc6a6bba7c587bec0a1f733b333dc2650.tar.gz
phosphor-bmc-code-mgmt-2285fe0fc6a6bba7c587bec0a1f733b333dc2650.zip
Enable clang code format
Change-Id: Ia899858c11cff6e4fa26b820b35b1e5dca1b57df Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
-rw-r--r--.clang-format85
-rw-r--r--activation.cpp104
-rw-r--r--activation.hpp516
-rw-r--r--download_manager.cpp9
-rw-r--r--download_manager.hpp34
-rw-r--r--download_manager_main.cpp6
-rw-r--r--elog-errors.hpp53
-rw-r--r--image_manager.cpp39
-rw-r--r--image_manager.hpp72
-rw-r--r--image_manager_main.cpp9
-rw-r--r--item_updater.cpp249
-rw-r--r--item_updater.hpp368
-rw-r--r--serialize.cpp13
-rwxr-xr-xtest/utest.cpp32
-rw-r--r--version.cpp11
-rw-r--r--version.hpp224
-rw-r--r--watch.cpp33
-rw-r--r--watch.hpp67
18 files changed, 930 insertions, 994 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..bbc1bb1
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,85 @@
+---
+Language: Cpp
+# BasedOnStyle: LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: true
+ AfterEnum: true
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: true
+ AfterStruct: true
+ AfterUnion: true
+ BeforeCatch: true
+ BeforeElse: true
+ IndentBraces: false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: AfterColon
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: true
+PointerAlignment: Left
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IndentCaseLabels: true
+IndentWidth: 4
+IndentWrappedFunctionNames: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Right
+ReflowComments: true
+SortIncludes: false
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 4
+UseTab: Never
+...
+
diff --git a/activation.cpp b/activation.cpp
index a102bf3..823f1fb 100644
--- a/activation.cpp
+++ b/activation.cpp
@@ -17,10 +17,8 @@ using namespace phosphor::logging;
void Activation::subscribeToSystemdSignals()
{
- auto method = this->bus.new_method_call(SYSTEMD_BUSNAME,
- SYSTEMD_PATH,
- SYSTEMD_INTERFACE,
- "Subscribe");
+ auto method = this->bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "Subscribe");
this->bus.call_noreply(method);
return;
@@ -28,17 +26,14 @@ void Activation::subscribeToSystemdSignals()
void Activation::unsubscribeFromSystemdSignals()
{
- auto method = this->bus.new_method_call(SYSTEMD_BUSNAME,
- SYSTEMD_PATH,
- SYSTEMD_INTERFACE,
- "Unsubscribe");
+ auto method = this->bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "Unsubscribe");
this->bus.call_noreply(method);
return;
}
-auto Activation::activation(Activations value) ->
- Activations
+auto Activation::activation(Activations value) -> Activations
{
if ((value != softwareServer::Activation::Activations::Active) &&
@@ -55,33 +50,25 @@ auto Activation::activation(Activations value) ->
if (!activationProgress)
{
- activationProgress = std::make_unique<ActivationProgress>(bus,
- path);
+ activationProgress =
+ std::make_unique<ActivationProgress>(bus, path);
}
if (!activationBlocksTransition)
{
activationBlocksTransition =
- std::make_unique<ActivationBlocksTransition>(
- bus,
- path);
+ std::make_unique<ActivationBlocksTransition>(bus, path);
}
- auto method = bus.new_method_call(
- SYSTEMD_BUSNAME,
- SYSTEMD_PATH,
- SYSTEMD_INTERFACE,
- "StartUnit");
+ auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "StartUnit");
method.append("obmc-flash-bmc-ubirw.service", "replace");
bus.call_noreply(method);
- auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId +
- ".service";
- method = bus.new_method_call(
- SYSTEMD_BUSNAME,
- SYSTEMD_PATH,
- SYSTEMD_INTERFACE,
- "StartUnit");
+ auto roServiceFile =
+ "obmc-flash-bmc-ubiro@" + versionId + ".service";
+ method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "StartUnit");
method.append(roServiceFile, "replace");
bus.call_noreply(method);
@@ -95,12 +82,8 @@ auto Activation::activation(Activations value) ->
if (!redundancyPriority)
{
- redundancyPriority =
- std::make_unique<RedundancyPriority>(
- bus,
- path,
- *this,
- 0);
+ redundancyPriority = std::make_unique<RedundancyPriority>(
+ bus, path, *this, 0);
}
}
else
@@ -122,7 +105,7 @@ auto Activation::activation(Activations value) ->
parent.createActiveAssociation(path);
return softwareServer::Activation::activation(
- softwareServer::Activation::Activations::Active);
+ softwareServer::Activation::Activations::Active);
}
}
}
@@ -137,12 +120,11 @@ auto Activation::activation(Activations value) ->
void Activation::deleteImageManagerObject()
{
// Call the Delete object for <versionID> inside image_manager
- auto method = this->bus.new_method_call(VERSION_BUSNAME,
- path.c_str(),
- "xyz.openbmc_project.Object.Delete",
- "Delete");
+ auto method = this->bus.new_method_call(VERSION_BUSNAME, path.c_str(),
+ "xyz.openbmc_project.Object.Delete",
+ "Delete");
auto mapperResponseMsg = bus.call(method);
- //Check that the bus call didn't result in an error
+ // Check that the bus call didn't result in an error
if (mapperResponseMsg.is_method_error())
{
log<level::ERR>("Error in Deleting image from image manager",
@@ -151,8 +133,8 @@ void Activation::deleteImageManagerObject()
}
}
-auto Activation::requestedActivation(RequestedActivations value) ->
- RequestedActivations
+auto Activation::requestedActivation(RequestedActivations value)
+ -> RequestedActivations
{
rwVolumeCreated = false;
roVolumeCreated = false;
@@ -160,16 +142,15 @@ auto Activation::requestedActivation(RequestedActivations value) ->
if ((value == softwareServer::Activation::RequestedActivations::Active) &&
(softwareServer::Activation::requestedActivation() !=
- softwareServer::Activation::RequestedActivations::Active))
+ softwareServer::Activation::RequestedActivations::Active))
{
if ((softwareServer::Activation::activation() ==
- softwareServer::Activation::Activations::Ready) ||
+ softwareServer::Activation::Activations::Ready) ||
(softwareServer::Activation::activation() ==
- softwareServer::Activation::Activations::Failed))
+ softwareServer::Activation::Activations::Failed))
{
Activation::activation(
- softwareServer::Activation::Activations::Activating);
-
+ softwareServer::Activation::Activations::Activating);
}
}
return softwareServer::Activation::requestedActivation(value);
@@ -194,23 +175,23 @@ uint8_t RedundancyPriority::sdbusPriority(uint8_t value)
void Activation::unitStateChange(sdbusplus::message::message& msg)
{
if (softwareServer::Activation::activation() !=
- softwareServer::Activation::Activations::Activating)
+ softwareServer::Activation::Activations::Activating)
{
return;
}
- uint32_t newStateID {};
+ uint32_t newStateID{};
sdbusplus::message::object_path newStateObjPath;
std::string newStateUnit{};
std::string newStateResult{};
- //Read the msg and populate each variable
+ // Read the msg and populate each variable
msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult);
auto rwServiceFile = "obmc-flash-bmc-ubirw.service";
auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + ".service";
- auto ubootVarsServiceFile = "obmc-flash-bmc-updateubootvars@" + versionId +
- ".service";
+ auto ubootVarsServiceFile =
+ "obmc-flash-bmc-updateubootvars@" + versionId + ".service";
if (newStateUnit == rwServiceFile && newStateResult == "done")
{
@@ -229,20 +210,19 @@ void Activation::unitStateChange(sdbusplus::message::message& msg)
ubootEnvVarsUpdated = true;
}
- if (newStateUnit == rwServiceFile ||
- newStateUnit == roServiceFile ||
+ if (newStateUnit == rwServiceFile || newStateUnit == roServiceFile ||
newStateUnit == ubootVarsServiceFile)
{
if (newStateResult == "failed" || newStateResult == "dependency")
{
Activation::activation(
- softwareServer::Activation::Activations::Failed);
+ softwareServer::Activation::Activations::Failed);
}
else if ((rwVolumeCreated && roVolumeCreated) || // Volumes were created
(ubootEnvVarsUpdated)) // Enviroment variables were updated
{
Activation::activation(
- softwareServer::Activation::Activations::Activating);
+ softwareServer::Activation::Activations::Activating);
}
}
@@ -253,11 +233,8 @@ void ActivationBlocksTransition::enableRebootGuard()
{
log<level::INFO>("BMC image activating - BMC reboots are disabled.");
- auto method = bus.new_method_call(
- SYSTEMD_BUSNAME,
- SYSTEMD_PATH,
- SYSTEMD_INTERFACE,
- "StartUnit");
+ auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "StartUnit");
method.append("reboot-guard-enable.service", "replace");
bus.call_noreply(method);
}
@@ -266,11 +243,8 @@ void ActivationBlocksTransition::disableRebootGuard()
{
log<level::INFO>("BMC activation has ended - BMC reboots are re-enabled.");
- auto method = bus.new_method_call(
- SYSTEMD_BUSNAME,
- SYSTEMD_PATH,
- SYSTEMD_INTERFACE,
- "StartUnit");
+ auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "StartUnit");
method.append("reboot-guard-disable.service", "replace");
bus.call_noreply(method);
}
diff --git a/activation.hpp b/activation.hpp
index b2b9aec..6289278 100644
--- a/activation.hpp
+++ b/activation.hpp
@@ -15,12 +15,13 @@ namespace updater
{
using AssociationList =
- std::vector<std::tuple<std::string, std::string, std::string>>;
+ std::vector<std::tuple<std::string, std::string, std::string>>;
using ActivationInherit = sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::Software::server::Activation,
sdbusplus::org::openbmc::server::Associations>;
using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>;
+ sdbusplus::xyz::openbmc_project::Software::server::
+ ActivationBlocksTransition>;
using RedundancyPriorityInherit = sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
using ActivationProgressInherit = sdbusplus::server::object::object<
@@ -39,78 +40,73 @@ class RedundancyPriority;
*/
class RedundancyPriority : public RedundancyPriorityInherit
{
- public:
- /** @brief Constructs RedundancyPriority.
- *
- * @param[in] bus - The Dbus bus object
- * @param[in] path - The Dbus object path
- * @param[in] parent - Parent object.
- * @param[in] value - The redundancyPriority value
- * @param[in] freePriority - Call freePriorioty, default to true
- */
- RedundancyPriority(sdbusplus::bus::bus& bus,
- const std::string& path,
- Activation& parent,
- uint8_t value,
- bool freePriority=true) :
- RedundancyPriorityInherit(bus,
- path.c_str(), true),
- parent(parent),
- bus(bus),
- path(path)
+ public:
+ /** @brief Constructs RedundancyPriority.
+ *
+ * @param[in] bus - The Dbus bus object
+ * @param[in] path - The Dbus object path
+ * @param[in] parent - Parent object.
+ * @param[in] value - The redundancyPriority value
+ * @param[in] freePriority - Call freePriorioty, default to true
+ */
+ RedundancyPriority(sdbusplus::bus::bus& bus, const std::string& path,
+ Activation& parent, uint8_t value,
+ bool freePriority = true) :
+ RedundancyPriorityInherit(bus, path.c_str(), true),
+ parent(parent), bus(bus), path(path)
+ {
+ // Set Property
+ if (freePriority)
{
- // Set Property
- if (freePriority)
- {
- priority(value);
- }
- else
- {
- sdbusPriority(value);
- }
-
- std::vector<std::string> interfaces({interface});
- bus.emit_interfaces_added(path.c_str(), interfaces);
+ priority(value);
}
-
- ~RedundancyPriority()
+ else
{
- std::vector<std::string> interfaces({interface});
- bus.emit_interfaces_removed(path.c_str(), interfaces);
+ sdbusPriority(value);
}
- /** @brief Overriden Priority property set function, calls freePriority
- * to bump the duplicated priority values.
- *
- * @param[in] value - uint8_t
- *
- * @return Success or exception thrown
- */
- uint8_t priority(uint8_t value) override;
-
- /** @brief Non-Overriden Priority property set function
- *
- * @param[in] value - uint8_t
- *
- * @return Success or exception thrown
- */
- uint8_t sdbusPriority(uint8_t value);
-
- /** @brief Priority property get function
- *
- * @returns uint8_t - The Priority value
- */
- using RedundancyPriorityInherit::priority;
-
- /** @brief Parent Object. */
- Activation& parent;
-
- private:
- // TODO Remove once openbmc/openbmc#1975 is resolved
- static constexpr auto interface =
- "xyz.openbmc_project.Software.RedundancyPriority";
- sdbusplus::bus::bus& bus;
- std::string path;
+ std::vector<std::string> interfaces({interface});
+ bus.emit_interfaces_added(path.c_str(), interfaces);
+ }
+
+ ~RedundancyPriority()
+ {
+ std::vector<std::string> interfaces({interface});
+ bus.emit_interfaces_removed(path.c_str(), interfaces);
+ }
+
+ /** @brief Overriden Priority property set function, calls freePriority
+ * to bump the duplicated priority values.
+ *
+ * @param[in] value - uint8_t
+ *
+ * @return Success or exception thrown
+ */
+ uint8_t priority(uint8_t value) override;
+
+ /** @brief Non-Overriden Priority property set function
+ *
+ * @param[in] value - uint8_t
+ *
+ * @return Success or exception thrown
+ */
+ uint8_t sdbusPriority(uint8_t value);
+
+ /** @brief Priority property get function
+ *
+ * @returns uint8_t - The Priority value
+ */
+ using RedundancyPriorityInherit::priority;
+
+ /** @brief Parent Object. */
+ Activation& parent;
+
+ private:
+ // TODO Remove once openbmc/openbmc#1975 is resolved
+ static constexpr auto interface =
+ "xyz.openbmc_project.Software.RedundancyPriority";
+ sdbusplus::bus::bus& bus;
+ std::string path;
};
/** @class ActivationBlocksTransition
@@ -120,75 +116,71 @@ class RedundancyPriority : public RedundancyPriorityInherit
*/
class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
{
- public:
- /** @brief Constructs ActivationBlocksTransition.
- *
- * @param[in] bus - The Dbus bus object
- * @param[in] path - The Dbus object path
- */
- ActivationBlocksTransition(sdbusplus::bus::bus& bus,
- const std::string& path) :
- ActivationBlocksTransitionInherit(bus, path.c_str(), true),
- bus(bus),
- path(path)
- {
- std::vector<std::string> interfaces({interface});
- bus.emit_interfaces_added(path.c_str(), interfaces);
- enableRebootGuard();
- }
-
- ~ActivationBlocksTransition()
- {
- std::vector<std::string> interfaces({interface});
- bus.emit_interfaces_removed(path.c_str(), interfaces);
- disableRebootGuard();
- }
-
- private:
- // TODO Remove once openbmc/openbmc#1975 is resolved
- static constexpr auto interface =
- "xyz.openbmc_project.Software.ActivationBlocksTransition";
- sdbusplus::bus::bus& bus;
- std::string path;
-
- /** @brief Enables a Guard that blocks any BMC reboot commands */
- void enableRebootGuard();
-
- /** @brief Disables any guard that was blocking the BMC reboot */
- void disableRebootGuard();
+ public:
+ /** @brief Constructs ActivationBlocksTransition.
+ *
+ * @param[in] bus - The Dbus bus object
+ * @param[in] path - The Dbus object path
+ */
+ ActivationBlocksTransition(sdbusplus::bus::bus& bus,
+ const std::string& path) :
+ ActivationBlocksTransitionInherit(bus, path.c_str(), true),
+ bus(bus), path(path)
+ {
+ std::vector<std::string> interfaces({interface});
+ bus.emit_interfaces_added(path.c_str(), interfaces);
+ enableRebootGuard();
+ }
+
+ ~ActivationBlocksTransition()
+ {
+ std::vector<std::string> interfaces({interface});
+ bus.emit_interfaces_removed(path.c_str(), interfaces);
+ disableRebootGuard();
+ }
+
+ private:
+ // TODO Remove once openbmc/openbmc#1975 is resolved
+ static constexpr auto interface =
+ "xyz.openbmc_project.Software.ActivationBlocksTransition";
+ sdbusplus::bus::bus& bus;
+ std::string path;
+
+ /** @brief Enables a Guard that blocks any BMC reboot commands */
+ void enableRebootGuard();
+
+ /** @brief Disables any guard that was blocking the BMC reboot */
+ void disableRebootGuard();
};
class ActivationProgress : public ActivationProgressInherit
{
- public:
- /** @brief Constructs ActivationProgress.
- *
- * @param[in] bus - The Dbus bus object
- * @param[in] path - The Dbus object path
- */
- ActivationProgress(sdbusplus::bus::bus& bus,
- const std::string& path) :
- ActivationProgressInherit(bus, path.c_str(), true),
- bus(bus),
- path(path)
- {
- progress(0);
- std::vector<std::string> interfaces({interface});
- bus.emit_interfaces_added(path.c_str(), interfaces);
- }
-
- ~ActivationProgress()
- {
- std::vector<std::string> interfaces({interface});
- bus.emit_interfaces_removed(path.c_str(), interfaces);
- }
-
- private:
- // TODO Remove once openbmc/openbmc#1975 is resolved
- static constexpr auto interface =
- "xyz.openbmc_project.Software.ActivationProgress";
- sdbusplus::bus::bus& bus;
- std::string path;
+ public:
+ /** @brief Constructs ActivationProgress.
+ *
+ * @param[in] bus - The Dbus bus object
+ * @param[in] path - The Dbus object path
+ */
+ ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) :
+ ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path)
+ {
+ progress(0);
+ std::vector<std::string> interfaces({interface});
+ bus.emit_interfaces_added(path.c_str(), interfaces);
+ }
+
+ ~ActivationProgress()
+ {
+ std::vector<std::string> interfaces({interface});
+ bus.emit_interfaces_removed(path.c_str(), interfaces);
+ }
+
+ private:
+ // TODO Remove once openbmc/openbmc#1975 is resolved
+ static constexpr auto interface =
+ "xyz.openbmc_project.Software.ActivationProgress";
+ sdbusplus::bus::bus& bus;
+ std::string path;
};
/** @class Activation
@@ -198,137 +190,131 @@ class ActivationProgress : public ActivationProgressInherit
*/
class Activation : public ActivationInherit
{
- public:
- /** @brief Constructs Activation Software Manager
- *
- * @param[in] bus - The Dbus bus object
- * @param[in] path - The Dbus object path
- * @param[in] parent - Parent object.
- * @param[in] versionId - The software version id
- * @param[in] activationStatus - The status of Activation
- * @param[in] assocs - Association objects
- */
- Activation(sdbusplus::bus::bus& bus, const std::string& path,
- ItemUpdater& parent,
- std::string& versionId,
- sdbusplus::xyz::openbmc_project::Software::
- server::Activation::Activations activationStatus,
- AssociationList& assocs) :
- ActivationInherit(bus, path.c_str(), true),
- bus(bus),
- path(path),
- parent(parent),
- versionId(versionId),
- systemdSignals(
- bus,
- sdbusRule::type::signal() +
- sdbusRule::member("JobRemoved") +
- sdbusRule::path("/org/freedesktop/systemd1") +
- sdbusRule::interface(
- "org.freedesktop.systemd1.Manager"),
- std::bind(std::mem_fn(&Activation::unitStateChange),
- this, std::placeholders::_1))
- {
- // Enable systemd signals
- subscribeToSystemdSignals();
- // Set Properties.
- activation(activationStatus);
- associations(assocs);
-
- // Emit deferred signal.
- emit_object_added();
- }
-
- /** @brief Overloaded Activation property setter function
- *
- * @param[in] value - One of Activation::Activations
- *
- * @return Success or exception thrown
- */
- Activations activation(Activations value) override;
-
- /** @brief Activation */
- using ActivationInherit::activation;
-
- /** @brief Overloaded requestedActivation property setter function
- *
- * @param[in] value - One of Activation::RequestedActivations
- *
- * @return Success or exception thrown
- */
- RequestedActivations requestedActivation(RequestedActivations value)
- override;
-
- /** @brief Check if systemd state change is relevant to this object
- *
- * Instance specific interface to handle the detected systemd state
- * change
- *
- * @param[in] msg - Data associated with subscribed signal
- *
- */
- void unitStateChange(sdbusplus::message::message& msg);
-
- /**
- * @brief subscribe to the systemd signals
- *
- * This object needs to capture when it's systemd targets complete
- * so it can keep it's state updated
- *
- */
- void subscribeToSystemdSignals();
-
- /**
- * @brief unsubscribe from the systemd signals
- *
- * systemd signals are only of interest during the activation process.
- * Once complete, we want to unsubscribe to avoid unnecessary calls of
- * unitStateChange().
- *
- */
- void unsubscribeFromSystemdSignals();
-
- /**
- * @brief Deletes the version from Image Manager and the
- * untar image from image upload dir.
- */
- void deleteImageManagerObject();
-
- /** @brief Persistent sdbusplus DBus bus connection */
- sdbusplus::bus::bus& bus;
-
- /** @brief Persistent DBus object path */
- std::string path;
-
- /** @brief Parent Object. */
- ItemUpdater& parent;
-
- /** @brief Version id */
- std::string versionId;
-
- /** @brief Persistent ActivationBlocksTransition dbus object */
- std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
-
- /** @brief Persistent RedundancyPriority dbus object */
- std::unique_ptr<RedundancyPriority> redundancyPriority;
-
- /** @brief Persistent ActivationProgress dbus object */
- std::unique_ptr<ActivationProgress> activationProgress;
-
- /** @brief Used to subscribe to dbus systemd signals **/
- sdbusplus::bus::match_t systemdSignals;
-
- /** @brief Tracks whether the read-write volume has been created as
- * part of the activation process. **/
- bool rwVolumeCreated = false;
-
- /** @brief Tracks whether the read-only volume has been created as
- * part of the activation process. **/
- bool roVolumeCreated = false;
-
- /** @brief Tracks if the service that updates the U-Boot environment
- * variables has completed. **/
- bool ubootEnvVarsUpdated = false;
+ public:
+ /** @brief Constructs Activation Software Manager
+ *
+ * @param[in] bus - The Dbus bus object
+ * @param[in] path - The Dbus object path
+ * @param[in] parent - Parent object.
+ * @param[in] versionId - The software version id
+ * @param[in] activationStatus - The status of Activation
+ * @param[in] assocs - Association objects
+ */
+ Activation(sdbusplus::bus::bus& bus, const std::string& path,
+ ItemUpdater& parent, std::string& versionId,
+ sdbusplus::xyz::openbmc_project::Software::server::Activation::
+ Activations activationStatus,
+ AssociationList& assocs) :
+ ActivationInherit(bus, path.c_str(), true),
+ bus(bus), path(path), parent(parent), versionId(versionId),
+ systemdSignals(
+ bus,
+ sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
+ sdbusRule::path("/org/freedesktop/systemd1") +
+ sdbusRule::interface("org.freedesktop.systemd1.Manager"),
+ std::bind(std::mem_fn(&Activation::unitStateChange), this,
+ std::placeholders::_1))
+ {
+ // Enable systemd signals
+ subscribeToSystemdSignals();
+ // Set Properties.
+ activation(activationStatus);
+ associations(assocs);
+
+ // Emit deferred signal.
+ emit_object_added();
+ }
+
+ /** @brief Overloaded Activation property setter function
+ *
+ * @param[in] value - One of Activation::Activations
+ *
+ * @return Success or exception thrown
+ */
+ Activations activation(Activations value) override;
+
+ /** @brief Activation */
+ using ActivationInherit::activation;
+
+ /** @brief Overloaded requestedActivation property setter function
+ *
+ * @param[in] value - One of Activation::RequestedActivations
+ *
+ * @return Success or exception thrown
+ */
+ RequestedActivations
+ requestedActivation(RequestedActivations value) override;
+
+ /** @brief Check if systemd state change is relevant to this object
+ *
+ * Instance specific interface to handle the detected systemd state
+ * change
+ *
+ * @param[in] msg - Data associated with subscribed signal
+ *
+ */
+ void unitStateChange(sdbusplus::message::message& msg);
+
+ /**
+ * @brief subscribe to the systemd signals
+ *
+ * This object needs to capture when it's systemd targets complete
+ * so it can keep it's state updated
+ *
+ */
+ void subscribeToSystemdSignals();
+
+ /**
+ * @brief unsubscribe from the systemd signals
+ *
+ * systemd signals are only of interest during the activation process.
+ * Once complete, we want to unsubscribe to avoid unnecessary calls of
+ * unitStateChange().
+ *
+ */
+ void unsubscribeFromSystemdSignals();
+
+ /**
+ * @brief Deletes the version from Image Manager and the
+ * untar image from image upload dir.
+ */
+ void deleteImageManagerObject();
+
+ /** @brief Persistent sdbusplus DBus bus connection */
+ sdbusplus::bus::bus& bus;
+
+ /** @brief Persistent DBus object path */
+ std::string path;
+
+ /** @brief Parent Object. */
+ ItemUpdater& parent;
+
+ /** @brief Version id */
+ std::string versionId;
+
+ /** @brief Persistent ActivationBlocksTransition dbus object */
+ std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
+
+ /** @brief Persistent RedundancyPriority dbus object */
+ std::unique_ptr<RedundancyPriority> redundancyPriority;
+
+ /** @brief Persistent ActivationProgress dbus object */
+ std::unique_ptr<ActivationProgress> activationProgress;
+
+ /** @brief Used to subscribe to dbus systemd signals **/
+ sdbusplus::bus::match_t systemdSignals;
+
+ /** @brief Tracks whether the read-write volume has been created as
+ * part of the activation process. **/
+ bool rwVolumeCreated = false;
+
+ /** @brief Tracks whether the read-only volume has been created as
+ * part of the activation process. **/
+ bool roVolumeCreated = false;
+
+ /** @brief Tracks if the service that updates the U-Boot environment
+ * variables has completed. **/
+ bool ubootEnvVarsUpdated = false;
};
} // namespace updater
diff --git a/download_manager.cpp b/download_manager.cpp
index 1f31d32..3affd1d 100644
--- a/download_manager.cpp
+++ b/download_manager.cpp
@@ -22,8 +22,7 @@ using namespace sdbusplus::xyz::openbmc_project::Common::Error;
using namespace phosphor::logging;
namespace fs = std::experimental::filesystem;
-void Download::downloadViaTFTP(std::string fileName,
- std::string serverAddress)
+void Download::downloadViaTFTP(std::string fileName, std::string serverAddress)
{
using Argument = xyz::openbmc_project::Common::InvalidArgument;
@@ -69,10 +68,9 @@ void Download::downloadViaTFTP(std::string fileName,
if (pid == 0)
{
// child process
- execl("/usr/bin/tftp", "tftp", "-g", "-r", fileName.c_str(),
+ execl("/usr/bin/tftp", "tftp", "-g", "-r", fileName.c_str(),
serverAddress.c_str(), "-l",
- (std::string{IMG_UPLOAD_DIR} + '/' + fileName).c_str(),
- (char*)0);
+ (std::string{IMG_UPLOAD_DIR} + '/' + fileName).c_str(), (char*)0);
// execl only returns on fail
log<level::ERR>("Error occurred during the TFTP call");
elog<InternalFailure>();
@@ -89,4 +87,3 @@ void Download::downloadViaTFTP(std::string fileName,
} // namespace manager
} // namespace software
} // namespace phosphor
-
diff --git a/download_manager.hpp b/download_manager.hpp
index 2ee03fb..30e0b73 100644
--- a/download_manager.hpp
+++ b/download_manager.hpp
@@ -20,27 +20,25 @@ using DownloadInherit = sdbusplus::server::object::object<
*/
class Download : public DownloadInherit
{
- public:
- /** @brief Constructs Download Software Manager
- *
- * @param[in] bus - The Dbus bus object
- * @param[in] objPath - The Dbus object path
- */
- Download(sdbusplus::bus::bus& bus,
- const std::string& objPath) : DownloadInherit(
- bus, (objPath).c_str()) {};
+ public:
+ /** @brief Constructs Download Software Manager
+ *
+ * @param[in] bus - The Dbus bus object
+ * @param[in] objPath - The Dbus object path
+ */
+ Download(sdbusplus::bus::bus& bus, const std::string& objPath) :
+ DownloadInherit(bus, (objPath).c_str()){};
- /**
- * @brief Download the specified image via TFTP
- *
- * @param[in] fileName - The name of the file to transfer.
- * @param[in] serverAddress - The TFTP Server IP Address.
- **/
- void downloadViaTFTP(std::string fileName,
- std::string serverAddress) override;
+ /**
+ * @brief Download the specified image via TFTP
+ *
+ * @param[in] fileName - The name of the file to transfer.
+ * @param[in] serverAddress - The TFTP Server IP Address.
+ **/
+ void downloadViaTFTP(std::string fileName,
+ std::string serverAddress) override;
};
} // namespace manager
} // namespace software
} // namespace phosphor
-
diff --git a/download_manager_main.cpp b/download_manager_main.cpp
index e32e8c8..9ea37ad 100644
--- a/download_manager_main.cpp
+++ b/download_manager_main.cpp
@@ -7,11 +7,9 @@ int main(int argc, char* argv[])
auto bus = sdbusplus::bus::new_default();
// Add sdbusplus ObjectManager.
- sdbusplus::server::manager::manager objManager(bus,
- SOFTWARE_OBJPATH);
+ sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH);
- phosphor::software::manager::Download manager(bus,
- SOFTWARE_OBJPATH);
+ phosphor::software::manager::Download manager(bus, SOFTWARE_OBJPATH);
bus.request_name(DOWNLOAD_BUSNAME);
diff --git a/elog-errors.hpp b/elog-errors.hpp
index 5461ef6..a782ed0 100644
--- a/elog-errors.hpp
+++ b/elog-errors.hpp
@@ -21,7 +21,7 @@ namespace Version
{
namespace Error
{
- struct UnTarFailure;
+struct UnTarFailure;
} // namespace Error
} // namespace Version
} // namespace Software
@@ -41,7 +41,7 @@ namespace Version
{
namespace Error
{
- struct InternalFailure;
+struct InternalFailure;
} // namespace Error
} // namespace Version
} // namespace Software
@@ -61,7 +61,7 @@ namespace Version
{
namespace Error
{
- struct ManifestFileFailure;
+struct ManifestFileFailure;
} // namespace Error
} // namespace Version
} // namespace Software
@@ -69,7 +69,6 @@ namespace Error
} // namespace xyz
} // namespace sdbusplus
-
namespace phosphor
{
@@ -91,16 +90,17 @@ struct PATH
{
static constexpr auto str = "PATH=%s";
static constexpr auto str_short = "PATH";
- using type = std::tuple<std::decay_t<decltype(str)>,const char*>;
- explicit constexpr PATH(const char* a) : _entry(entry(str, a)) {};
+ using type = std::tuple<std::decay_t<decltype(str)>, const char*>;
+ explicit constexpr PATH(const char* a) : _entry(entry(str, a)){};
type _entry;
};
-} // namespace _UnTarFailure
+} // namespace _UnTarFailure
struct UnTarFailure : public sdbusplus::exception_t
{
- static constexpr auto errName = "xyz.openbmc_project.Software.Version.UnTarFailure";
+ static constexpr auto errName =
+ "xyz.openbmc_project.Software.Version.UnTarFailure";
static constexpr auto errDesc = "An error occurred during untar.";
static constexpr auto L = level::ERR;
using PATH = _UnTarFailure::PATH;
@@ -127,16 +127,15 @@ struct UnTarFailure : public sdbusplus::exception_t
} // namespace openbmc_project
} // namespace xyz
-
namespace details
{
template <>
-struct map_exception_type<sdbusplus::xyz::openbmc_project::Software::Version::Error::UnTarFailure>
+struct map_exception_type<
+ sdbusplus::xyz::openbmc_project::Software::Version::Error::UnTarFailure>
{
using type = xyz::openbmc_project::Software::Version::UnTarFailure;
};
-
}
namespace xyz
@@ -154,16 +153,17 @@ struct PATH
{
static constexpr auto str = "PATH=%s";
static constexpr auto str_short = "PATH";
- using type = std::tuple<std::decay_t<decltype(str)>,const char*>;
- explicit constexpr PATH(const char* a) : _entry(entry(str, a)) {};
+ using type = std::tuple<std::decay_t<decltype(str)>, const char*>;
+ explicit constexpr PATH(const char* a) : _entry(entry(str, a)){};
type _entry;
};
-} // namespace _ManifestFileFailure
+} // namespace _ManifestFileFailure
struct ManifestFileFailure : public sdbusplus::exception_t
{
- static constexpr auto errName = "xyz.openbmc_project.Software.Version.ManifestFileFailure";
+ static constexpr auto errName =
+ "xyz.openbmc_project.Software.Version.ManifestFileFailure";
static constexpr auto errDesc = "An error when reading the Manifest file.";
static constexpr auto L = level::ERR;
using PATH = _ManifestFileFailure::PATH;
@@ -190,16 +190,15 @@ struct ManifestFileFailure : public sdbusplus::exception_t
} // namespace openbmc_project
} // namespace xyz
-
namespace details
{
template <>
-struct map_exception_type<sdbusplus::xyz::openbmc_project::Software::Version::Error::ManifestFileFailure>
+struct map_exception_type<sdbusplus::xyz::openbmc_project::Software::Version::
+ Error::ManifestFileFailure>
{
using type = xyz::openbmc_project::Software::Version::ManifestFileFailure;
};
-
}
namespace xyz
@@ -217,17 +216,19 @@ struct FAIL
{
static constexpr auto str = "FAIL=%s";
static constexpr auto str_short = "FAIL";
- using type = std::tuple<std::decay_t<decltype(str)>,const char*>;
- explicit constexpr FAIL(const char* a) : _entry(entry(str, a)) {};
+ using type = std::tuple<std::decay_t<decltype(str)>, const char*>;
+ explicit constexpr FAIL(const char* a) : _entry(entry(str, a)){};
type _entry;
};
-} // namespace _InternalFailure
+} // namespace _InternalFailure
struct InternalFailure : public sdbusplus::exception_t
{
- static constexpr auto errName = "xyz.openbmc_project.Software.Version.InternalFailure";
- static constexpr auto errDesc = "The operation failed internally during processing the image.";
+ static constexpr auto errName =
+ "xyz.openbmc_project.Software.Version.InternalFailure";
+ static constexpr auto errDesc =
+ "The operation failed internally during processing the image.";
static constexpr auto L = level::ERR;
using FAIL = _InternalFailure::FAIL;
using metadata_types = std::tuple<FAIL>;
@@ -253,19 +254,17 @@ struct InternalFailure : public sdbusplus::exception_t
} // namespace openbmc_project
} // namespace xyz
-
namespace details
{
template <>
-struct map_exception_type<sdbusplus::xyz::openbmc_project::Software::Version::Error::InternalFailure>
+struct map_exception_type<
+ sdbusplus::xyz::openbmc_project::Software::Version::Error::InternalFailure>
{
using type = xyz::openbmc_project::Software::Version::InternalFailure;
};
-
}
-
} // namespace logging
} // namespace phosphor
diff --git a/image_manager.cpp b/image_manager.cpp
index 8ff0a5c..7c19866 100644
--- a/image_manager.cpp
+++ b/image_manager.cpp
@@ -28,14 +28,16 @@ using namespace sdbusplus::xyz::openbmc_project::Software::Version::Error;
namespace Software = phosphor::logging::xyz::openbmc_project::Software;
using ManifestFail = Software::Version::ManifestFileFailure;
using UnTarFail = Software::Version::UnTarFailure;
-using InternalFail= Software::Version::InternalFailure;
+using InternalFail = Software::Version::InternalFailure;
namespace fs = std::experimental::filesystem;
struct RemovablePath
{
fs::path path;
- RemovablePath(const fs::path& path) : path(path) {}
+ RemovablePath(const fs::path& path) : path(path)
+ {
+ }
~RemovablePath()
{
if (fs::exists(path))
@@ -59,7 +61,6 @@ int Manager::processImage(const std::string& tarFilePath)
entry("FILENAME=%s", tarFilePath.c_str()));
report<ManifestFileFailure>(ManifestFail::PATH(tarFilePath.c_str()));
return -1;
-
}
RemovablePath tarPathRemove(tarFilePath);
fs::path tmpDirPath(std::string{IMG_UPLOAD_DIR});
@@ -144,7 +145,7 @@ int Manager::processImage(const std::string& tarFilePath)
}
catch (const sdbusplus::exception::InvalidEnumString& e)
{
- log<level::ERR>("Error: Failed to convert manifest purpose to enum." \
+ log<level::ERR>("Error: Failed to convert manifest purpose to enum."
" Setting to Unknown.");
}
@@ -175,22 +176,16 @@ int Manager::processImage(const std::string& tarFilePath)
}
// Create Version object
- auto objPath = std::string{SOFTWARE_OBJPATH} + '/' + id;
+ auto objPath = std::string{SOFTWARE_OBJPATH} + '/' + id;
if (versions.find(id) == versions.end())
{
auto versionPtr = std::make_unique<Version>(
- bus,
- objPath,
- version,
- purpose,
- imageDirPath.string(),
- std::bind(&Manager::erase,
- this,
- std::placeholders::_1));
+ bus, objPath, version, purpose, imageDirPath.string(),
+ std::bind(&Manager::erase, this, std::placeholders::_1));
versionPtr->deleteObject =
- std::make_unique<phosphor::software::manager::Delete>(
- bus, objPath, *versionPtr);
+ std::make_unique<phosphor::software::manager::Delete>(bus, objPath,
+ *versionPtr);
versions.insert(std::make_pair(id, std::move(versionPtr)));
}
else
@@ -211,9 +206,10 @@ void Manager::erase(std::string entryId)
if (it->second->isFunctional())
{
- log<level::ERR>(("Error: Version " + entryId + \
- " is currently running on the BMC." \
- " Unable to remove.").c_str());
+ log<level::ERR>(("Error: Version " + entryId +
+ " is currently running on the BMC."
+ " Unable to remove.")
+ .c_str());
return;
}
@@ -242,8 +238,7 @@ int Manager::unTar(const std::string& tarFilePath,
return -1;
}
- log<level::INFO>("Untaring",
- entry("FILENAME=%s", tarFilePath.c_str()),
+ log<level::INFO>("Untaring", entry("FILENAME=%s", tarFilePath.c_str()),
entry("EXTRACTIONDIR=%s", extractDirPath.c_str()));
int status = 0;
pid_t pid = fork();
@@ -251,8 +246,8 @@ int Manager::unTar(const std::string& tarFilePath,
if (pid == 0)
{
// child process
- execl("/bin/tar", "tar", "-xf", tarFilePath.c_str(),
- "-C", extractDirPath.c_str(), (char*)0);
+ execl("/bin/tar", "tar", "-xf", tarFilePath.c_str(), "-C",
+ extractDirPath.c_str(), (char*)0);
// execl only returns on fail
log<level::ERR>("Failed to execute untar file",
entry("FILENAME=%s", tarFilePath.c_str()));
diff --git a/image_manager.hpp b/image_manager.hpp
index 4938823..ccd82a0 100644
--- a/image_manager.hpp
+++ b/image_manager.hpp
@@ -16,47 +16,47 @@ namespace manager
*/
class Manager
{
- public:
- /** @brief Constructs Manager Class
- *
- * @param[in] bus - The Dbus bus object
- */
- Manager(sdbusplus::bus::bus& bus) : bus(bus){};
+ public:
+ /** @brief Constructs Manager Class
+ *
+ * @param[in] bus - The Dbus bus object
+ */
+ Manager(sdbusplus::bus::bus& bus) : bus(bus){};
- /**
- * @brief Verify and untar the tarball. Verify the manifest file.
- * Create and populate the version and filepath interfaces.
- *
- * @param[in] tarballFilePath - Tarball path.
- * @param[out] result - 0 if successful.
- */
- int processImage(const std::string& tarballFilePath);
+ /**
+ * @brief Verify and untar the tarball. Verify the manifest file.
+ * Create and populate the version and filepath interfaces.
+ *
+ * @param[in] tarballFilePath - Tarball path.
+ * @param[out] result - 0 if successful.
+ */
+ int processImage(const std::string& tarballFilePath);
- /**
- * @brief Erase specified entry d-bus object
- * and deletes the image file.
- *
- * @param[in] entryId - unique identifier of the entry
- */
- void erase(std::string entryId);
+ /**
+ * @brief Erase specified entry d-bus object
+ * and deletes the image file.
+ *
+ * @param[in] entryId - unique identifier of the entry
+ */
+ void erase(std::string entryId);
- private:
- /** @brief Persistent map of Version dbus objects and their
- * version id */
- std::map<std::string, std::unique_ptr<Version>> versions;
+ private:
+ /** @brief Persistent map of Version dbus objects and their
+ * version id */
+ std::map<std::string, std::unique_ptr<Version>> versions;
- /** @brief Persistent sdbusplus DBus bus connection. */
- sdbusplus::bus::bus& bus;
+ /** @brief Persistent sdbusplus DBus bus connection. */
+ sdbusplus::bus::bus& bus;
- /**
- * @brief Untar the tarball.
- *
- * @param[in] tarballFilePath - Tarball path.
- * @param[in] extractDirPath - Dir path to extract tarball ball to.
- * @param[out] result - 0 if successful.
- */
- static int unTar(const std::string& tarballFilePath,
- const std::string& extractDirPath);
+ /**
+ * @brief Untar the tarball.
+ *
+ * @param[in] tarballFilePath - Tarball path.
+ * @param[in] extractDirPath - Dir path to extract tarball ball to.
+ * @param[out] result - 0 if successful.
+ */
+ static int unTar(const std::string& tarballFilePath,
+ const std::string& extractDirPath);
};
} // namespace manager
diff --git a/image_manager_main.cpp b/image_manager_main.cpp
index 71cf37d..419b467 100644
--- a/image_manager_main.cpp
+++ b/image_manager_main.cpp
@@ -14,18 +14,15 @@ int main(int argc, char* argv[])
sd_event* loop = nullptr;
sd_event_default(&loop);
- sdbusplus::server::manager::manager objManager(bus,
- SOFTWARE_OBJPATH);
+ sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH);
bus.request_name(VERSION_BUSNAME);
try
{
phosphor::software::manager::Manager imageManager(bus);
phosphor::software::manager::Watch watch(
- loop,
- std::bind(std::mem_fn(&Manager::processImage),
- &imageManager,
- std::placeholders::_1));
+ loop, std::bind(std::mem_fn(&Manager::processImage), &imageManager,
+ std::placeholders::_1));
bus.attach_event(loop, SD_EVENT_PRIORITY_NORMAL);
sd_event_loop(loop);
}
diff --git a/item_updater.cpp b/item_updater.cpp
index 30e6b0a..4d07ac9 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -28,10 +28,8 @@ using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Software::Version::Error;
namespace fs = std::experimental::filesystem;
-const std::vector<std::string> bmcImages = { "image-kernel",
- "image-rofs",
- "image-rwfs",
- "image-u-boot" };
+const std::vector<std::string> bmcImages = {"image-kernel", "image-rofs",
+ "image-rwfs", "image-u-boot"};
void ItemUpdater::createActivation(sdbusplus::message::message& msg)
{
@@ -45,9 +43,8 @@ void ItemUpdater::createActivation(sdbusplus::message::message& msg)
mesg::object_path objPath;
auto purpose = VersionPurpose::Unknown;
std::string version;
- std::map<std::string,
- std::map<std::string,
- mesg::variant<std::string>>> interfaces;
+ std::map<std::string, std::map<std::string, mesg::variant<std::string>>>
+ interfaces;
msg.read(objPath, interfaces);
std::string path(std::move(objPath));
std::string filePath;
@@ -61,7 +58,7 @@ void ItemUpdater::createActivation(sdbusplus::message::message& msg)
if (property.first == "Purpose")
{
auto value = SVersion::convertVersionPurposeFromString(
- variant_ns::get<std::string>(property.second));
+ variant_ns::get<std::string>(property.second));
if (value == VersionPurpose::BMC ||
value == VersionPurpose::System)
{
@@ -85,8 +82,7 @@ void ItemUpdater::createActivation(sdbusplus::message::message& msg)
}
}
}
- if (version.empty() ||
- filePath.empty() ||
+ if (version.empty() || filePath.empty() ||
purpose == VersionPurpose::Unknown)
{
return;
@@ -108,41 +104,29 @@ void ItemUpdater::createActivation(sdbusplus::message::message& msg)
// Determine the Activation state by processing the given image dir.
auto activationState = server::Activation::Activations::Invalid;
ItemUpdater::ActivationStatus result =
- ItemUpdater::validateSquashFSImage(filePath);
+ ItemUpdater::validateSquashFSImage(filePath);
AssociationList associations = {};
if (result == ItemUpdater::ActivationStatus::ready)
{
activationState = server::Activation::Activations::Ready;
// Create an association to the BMC inventory item
- associations.emplace_back(std::make_tuple(
- ACTIVATION_FWD_ASSOCIATION,
- ACTIVATION_REV_ASSOCIATION,
- bmcInventoryPath));
+ associations.emplace_back(
+ std::make_tuple(ACTIVATION_FWD_ASSOCIATION,
+ ACTIVATION_REV_ASSOCIATION, bmcInventoryPath));
}
activations.insert(std::make_pair(
- versionId,
- std::make_unique<Activation>(
- bus,
- path,
- *this,
- versionId,
- activationState,
- associations)));
+ versionId,
+ std::make_unique<Activation>(bus, path, *this, versionId,
+ activationState, associations)));
auto versionPtr = std::make_unique<VersionClass>(
- bus,
- path,
- version,
- purpose,
- filePath,
- std::bind(&ItemUpdater::erase,
- this,
- std::placeholders::_1));
+ bus, path, version, purpose, filePath,
+ std::bind(&ItemUpdater::erase, this, std::placeholders::_1));
versionPtr->deleteObject =
- std::make_unique<phosphor::software::manager::Delete>(
- bus, path, *versionPtr);
+ std::make_unique<phosphor::software::manager::Delete>(bus, path,
+ *versionPtr);
versions.insert(std::make_pair(versionId, std::move(versionPtr)));
}
return;
@@ -162,8 +146,8 @@ void ItemUpdater::processBMCImage()
static const auto BMC_RO_PREFIX_LEN = strlen(BMC_ROFS_PREFIX);
// Check if the BMC_RO_PREFIXis the prefix of the iter.path
- if (0 == iter.path().native().compare(0, BMC_RO_PREFIX_LEN,
- BMC_ROFS_PREFIX))
+ if (0 ==
+ iter.path().native().compare(0, BMC_RO_PREFIX_LEN, BMC_ROFS_PREFIX))
{
// The versionId is extracted from the path
// for example /media/ro-2a1022fe.
@@ -171,16 +155,18 @@ void ItemUpdater::processBMCImage()
auto osRelease = iter.path() / OS_RELEASE_FILE;
if (!fs::is_regular_file(osRelease))
{
- log<level::ERR>("Failed to read osRelease",
- entry("FILENAME=%s", osRelease.string().c_str()));
+ log<level::ERR>(
+ "Failed to read osRelease",
+ entry("FILENAME=%s", osRelease.string().c_str()));
ItemUpdater::erase(id);
continue;
}
auto version = VersionClass::getBMCVersion(osRelease);
if (version.empty())
{
- log<level::ERR>("Failed to read version from osRelease",
- entry("FILENAME=%s", osRelease.string().c_str()));
+ log<level::ERR>(
+ "Failed to read version from osRelease",
+ entry("FILENAME=%s", osRelease.string().c_str()));
activationState = server::Activation::Activations::Invalid;
}
@@ -199,9 +185,8 @@ void ItemUpdater::processBMCImage()
{
// Create an association to the BMC inventory item
associations.emplace_back(std::make_tuple(
- ACTIVATION_FWD_ASSOCIATION,
- ACTIVATION_REV_ASSOCIATION,
- bmcInventoryPath));
+ ACTIVATION_FWD_ASSOCIATION, ACTIVATION_REV_ASSOCIATION,
+ bmcInventoryPath));
// Create an active association since this image is active
createActiveAssociation(path);
@@ -209,35 +194,21 @@ void ItemUpdater::processBMCImage()
// Create Version instance for this version.
auto versionPtr = std::make_unique<VersionClass>(
- bus,
- path,
- version,
- purpose,
- "",
- std::bind(&ItemUpdater::erase,
- this,
- std::placeholders::_1));
+ bus, path, version, purpose, "",
+ std::bind(&ItemUpdater::erase, this, std::placeholders::_1));
auto isVersionFunctional = versionPtr->isFunctional();
if (!isVersionFunctional)
{
versionPtr->deleteObject =
- std::make_unique<phosphor::software::manager::Delete>(
- bus, path, *versionPtr);
+ std::make_unique<phosphor::software::manager::Delete>(
+ bus, path, *versionPtr);
}
- versions.insert(std::make_pair(
- id,
- std::move(versionPtr)));
+ versions.insert(std::make_pair(id, std::move(versionPtr)));
// Create Activation instance for this version.
activations.insert(std::make_pair(
- id,
- std::make_unique<Activation>(
- bus,
- path,
- *this,
- id,
- activationState,
- associations)));
+ id, std::make_unique<Activation>(
+ bus, path, *this, id, activationState, associations)));
// If Active, create RedundancyPriority instance for this version.
if (activationState == server::Activation::Activations::Active)
@@ -252,16 +223,13 @@ void ItemUpdater::processBMCImage()
else
{
log<level::ERR>("Unable to restore priority from file.",
- entry("VERSIONID=%s", id.c_str()));
+ entry("VERSIONID=%s", id.c_str()));
}
}
activations.find(id)->second->redundancyPriority =
- std::make_unique<RedundancyPriority>(
- bus,
- path,
- *(activations.find(id)->second),
- priority,
- false);
+ std::make_unique<RedundancyPriority>(
+ bus, path, *(activations.find(id)->second), priority,
+ false);
}
}
}
@@ -299,9 +267,9 @@ void ItemUpdater::erase(std::string entryId)
{
if (it->second->isFunctional())
{
- log<level::ERR>(("Error: Version " + entryId + \
- " is currently running on the BMC." \
- " Unable to remove.").c_str());
+ log<level::ERR>("Error: Version is currently running on the BMC. "
+ "Unable to remove.",
+ entry("VERSIONID=%s", entryId.c_str()));
return;
}
@@ -318,18 +286,15 @@ void ItemUpdater::erase(std::string entryId)
removeReadOnlyPartition(entryId);
removeFile(entryId);
- log<level::ERR>(("Error: Failed to find version " + entryId + \
- " in item updater versions map." \
- " Unable to remove.").c_str());
+ log<level::ERR>("Error: Failed to find version in item updater "
+ "versions map. Unable to remove.",
+ entry("VERSIONID=%s", entryId.c_str()));
}
// Remove the priority environment variable.
auto serviceFile = "obmc-flash-bmc-setenv@" + entryId + ".service";
- auto method = bus.new_method_call(
- SYSTEMD_BUSNAME,
- SYSTEMD_PATH,
- SYSTEMD_INTERFACE,
- "StartUnit");
+ auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "StartUnit");
method.append(serviceFile, "replace");
bus.call_noreply(method);
@@ -337,9 +302,9 @@ void ItemUpdater::erase(std::string entryId)
auto ita = activations.find(entryId);
if (ita == activations.end())
{
- log<level::ERR>(("Error: Failed to find version " + entryId + \
- " in item updater activations map." \
- " Unable to remove.").c_str());
+ log<level::ERR>("Error: Failed to find version in item updater "
+ "activations map. Unable to remove.",
+ entry("VERSIONID=%s", entryId.c_str()));
}
else
{
@@ -367,17 +332,14 @@ void ItemUpdater::deleteAll()
}
// Remove any volumes that do not match current versions.
- auto method = bus.new_method_call(
- SYSTEMD_BUSNAME,
- SYSTEMD_PATH,
- SYSTEMD_INTERFACE,
- "StartUnit");
+ auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "StartUnit");
method.append("obmc-flash-bmc-cleanup.service", "replace");
bus.call_noreply(method);
}
-ItemUpdater::ActivationStatus ItemUpdater::validateSquashFSImage(
- const std::string& filePath)
+ItemUpdater::ActivationStatus
+ ItemUpdater::validateSquashFSImage(const std::string& filePath)
{
bool invalid = false;
@@ -414,25 +376,23 @@ void ItemUpdater::freePriority(uint8_t value, const std::string& versionId)
if (intf.second->redundancyPriority)
{
priorityMap.insert(std::make_pair(
- intf.first,
- intf.second->redundancyPriority.get()->priority()));
+ intf.first, intf.second->redundancyPriority.get()->priority()));
}
}
// Lambda function to compare 2 priority values, use <= to allow duplicates
- typedef std::function<bool(
- std::pair<std::string, uint8_t>,
- std::pair<std::string, uint8_t>)> cmpPriority;
- cmpPriority cmpPriorityFunc = [](
- std::pair<std::string, uint8_t> priority1,
- std::pair<std::string, uint8_t> priority2)
- {
- return priority1.second <= priority2.second;
- };
+ typedef std::function<bool(std::pair<std::string, uint8_t>,
+ std::pair<std::string, uint8_t>)>
+ cmpPriority;
+ cmpPriority cmpPriorityFunc =
+ [](std::pair<std::string, uint8_t> priority1,
+ std::pair<std::string, uint8_t> priority2) {
+ return priority1.second <= priority2.second;
+ };
// Sort versions by ascending priority
std::set<std::pair<std::string, uint8_t>, cmpPriority> prioritySet(
- priorityMap.begin(), priorityMap.end(), cmpPriorityFunc);
+ priorityMap.begin(), priorityMap.end(), cmpPriorityFunc);
auto freePriorityValue = value;
for (auto& element : prioritySet)
@@ -446,7 +406,7 @@ void ItemUpdater::freePriority(uint8_t value, const std::string& versionId)
++freePriorityValue;
auto it = activations.find(element.first);
it->second->redundancyPriority.get()->sdbusPriority(
- freePriorityValue);
+ freePriorityValue);
}
}
@@ -461,11 +421,8 @@ void ItemUpdater::freePriority(uint8_t value, const std::string& versionId)
void ItemUpdater::reset()
{
// Mark the read-write partition for recreation upon reboot.
- auto method = bus.new_method_call(
- SYSTEMD_BUSNAME,
- SYSTEMD_PATH,
- SYSTEMD_INTERFACE,
- "StartUnit");
+ auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "StartUnit");
method.append("obmc-flash-bmc-setenv@rwreset\\x3dtrue.service", "replace");
bus.call_noreply(method);
@@ -476,15 +433,11 @@ void ItemUpdater::reset()
void ItemUpdater::removeReadOnlyPartition(std::string versionId)
{
- auto serviceFile = "obmc-flash-bmc-ubiro-remove@" + versionId +
- ".service";
+ auto serviceFile = "obmc-flash-bmc-ubiro-remove@" + versionId + ".service";
// Remove the read-only partitions.
- auto method = bus.new_method_call(
- SYSTEMD_BUSNAME,
- SYSTEMD_PATH,
- SYSTEMD_INTERFACE,
- "StartUnit");
+ auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "StartUnit");
method.append(serviceFile, "replace");
bus.call_noreply(method);
}
@@ -496,30 +449,21 @@ bool ItemUpdater::fieldModeEnabled(bool value)
{
control::FieldMode::fieldModeEnabled(value);
- auto method = bus.new_method_call(
- SYSTEMD_BUSNAME,
- SYSTEMD_PATH,
- SYSTEMD_INTERFACE,
- "StartUnit");
+ auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "StartUnit");
method.append("obmc-flash-bmc-setenv@fieldmode\\x3dtrue.service",
"replace");
bus.call_noreply(method);
- method = bus.new_method_call(
- SYSTEMD_BUSNAME,
- SYSTEMD_PATH,
- SYSTEMD_INTERFACE,
- "StopUnit");
+ method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "StopUnit");
method.append("usr-local.mount", "replace");
bus.call_noreply(method);
std::vector<std::string> usrLocal = {"usr-local.mount"};
- method = bus.new_method_call(
- SYSTEMD_BUSNAME,
- SYSTEMD_PATH,
- SYSTEMD_INTERFACE,
- "MaskUnitFiles");
+ method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "MaskUnitFiles");
method.append(usrLocal, false, true);
bus.call_noreply(method);
}
@@ -542,10 +486,8 @@ void ItemUpdater::restoreFieldModeStatus()
void ItemUpdater::setBMCInventoryPath()
{
auto depth = 0;
- auto mapperCall = bus.new_method_call(MAPPER_BUSNAME,
- MAPPER_PATH,
- MAPPER_INTERFACE,
- "GetSubTreePaths");
+ auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
+ MAPPER_INTERFACE, "GetSubTreePaths");
mapperCall.append(INVENTORY_PATH);
mapperCall.append(depth);
@@ -573,17 +515,15 @@ void ItemUpdater::setBMCInventoryPath()
void ItemUpdater::createActiveAssociation(const std::string& path)
{
- assocs.emplace_back(std::make_tuple(ACTIVE_FWD_ASSOCIATION,
- ACTIVE_REV_ASSOCIATION,
- path));
+ assocs.emplace_back(
+ std::make_tuple(ACTIVE_FWD_ASSOCIATION, ACTIVE_REV_ASSOCIATION, path));
associations(assocs);
}
void ItemUpdater::createFunctionalAssociation(const std::string& path)
{
assocs.emplace_back(std::make_tuple(FUNCTIONAL_FWD_ASSOCIATION,
- FUNCTIONAL_REV_ASSOCIATION,
- path));
+ FUNCTIONAL_REV_ASSOCIATION, path));
associations(assocs);
}
@@ -623,17 +563,14 @@ bool ItemUpdater::isLowestPriority(uint8_t value)
void ItemUpdater::updateUbootEnvVars(const std::string& versionId)
{
- auto method = bus.new_method_call(
- SYSTEMD_BUSNAME,
- SYSTEMD_PATH,
- SYSTEMD_INTERFACE,
- "StartUnit");
- auto updateEnvVarsFile = "obmc-flash-bmc-updateubootvars@" + versionId +
- ".service";
+ auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "StartUnit");
+ auto updateEnvVarsFile =
+ "obmc-flash-bmc-updateubootvars@" + versionId + ".service";
method.append(updateEnvVarsFile, "replace");
auto result = bus.call(method);
- //Check that the bus call didn't result in an error
+ // Check that the bus call didn't result in an error
if (result.is_method_error())
{
log<level::ERR>("Failed to update u-boot env variables",
@@ -644,7 +581,7 @@ void ItemUpdater::updateUbootEnvVars(const std::string& versionId)
void ItemUpdater::resetUbootEnvVars()
{
decltype(activations.begin()->second->redundancyPriority.get()->priority())
- lowestPriority = std::numeric_limits<uint8_t>::max();
+ lowestPriority = std::numeric_limits<uint8_t>::max();
decltype(activations.begin()->second->versionId) lowestPriorityVersion;
for (const auto& intf : activations)
{
@@ -654,8 +591,7 @@ void ItemUpdater::resetUbootEnvVars()
continue;
}
- if (intf.second->redundancyPriority.get()->priority()
- <= lowestPriority)
+ if (intf.second->redundancyPriority.get()->priority() <= lowestPriority)
{
lowestPriority = intf.second->redundancyPriority.get()->priority();
lowestPriorityVersion = intf.second->versionId;
@@ -671,15 +607,16 @@ void ItemUpdater::freeSpace()
// Versions with the highest priority in front
std::priority_queue<std::pair<int, std::string>,
std::vector<std::pair<int, std::string>>,
- std::less<std::pair<int, std::string>>> versionsPQ;
+ std::less<std::pair<int, std::string>>>
+ versionsPQ;
std::size_t count = 0;
for (const auto& iter : activations)
{
if ((iter.second.get()->activation() ==
- server::Activation::Activations::Active) ||
+ server::Activation::Activations::Active) ||
(iter.second.get()->activation() ==
- server::Activation::Activations::Failed))
+ server::Activation::Activations::Failed))
{
count++;
// Don't put the functional version on the queue since we can't
@@ -689,8 +626,8 @@ void ItemUpdater::freeSpace()
continue;
}
versionsPQ.push(std::make_pair(
- iter.second->redundancyPriority.get()->priority(),
- iter.second->versionId));
+ iter.second->redundancyPriority.get()->priority(),
+ iter.second->versionId));
}
}
diff --git a/item_updater.hpp b/item_updater.hpp
index 61be15d..d4d72bd 100644
--- a/item_updater.hpp
+++ b/item_updater.hpp
@@ -16,202 +16,198 @@ namespace updater
{
using ItemUpdaterInherit = sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Common::server::FactoryReset,
- sdbusplus::xyz::openbmc_project::Control::server::FieldMode,
- sdbusplus::org::openbmc::server::Associations,
- sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
+ sdbusplus::xyz::openbmc_project::Common::server::FactoryReset,
+ sdbusplus::xyz::openbmc_project::Control::server::FieldMode,
+ sdbusplus::org::openbmc::server::Associations,
+ sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
namespace MatchRules = sdbusplus::bus::match::rules;
using VersionClass = phosphor::software::manager::Version;
using AssociationList =
- std::vector<std::tuple<std::string, std::string, std::string>>;
+ std::vector<std::tuple<std::string, std::string, std::string>>;
/** @class ItemUpdater
* @brief Manages the activation of the BMC version items.
*/
class ItemUpdater : public ItemUpdaterInherit
{
- public:
- /*
- * @brief Types of Activation status for image validation.
- */
- enum class ActivationStatus
- {
- ready,
- invalid,
- active
- };
-
- /** @brief Constructs ItemUpdater
- *
- * @param[in] bus - The D-Bus bus object
- */
- ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
- ItemUpdaterInherit(bus, path.c_str(), false),
- bus(bus),
- versionMatch(
- bus,
- MatchRules::interfacesAdded() +
- MatchRules::path("/xyz/openbmc_project/software"),
- std::bind(
- std::mem_fn(&ItemUpdater::createActivation),
- this,
- std::placeholders::_1))
- {
- setBMCInventoryPath();
- processBMCImage();
- restoreFieldModeStatus();
- emit_object_added();
- };
-
- /** @brief Sets the given priority free by incrementing
- * any existing priority with the same value by 1
- *
- * @param[in] value - The priority that needs to be set free.
- * @param[in] versionId - The Id of the version for which we
- * are trying to free up the priority.
- * @return None
- */
- void freePriority(uint8_t value, const std::string& versionId);
-
- /**
- * @brief Create and populate the active BMC Version.
- */
- void processBMCImage();
-
- /**
- * @brief Erase specified entry D-Bus object
- * if Action property is not set to Active
- *
- * @param[in] entryId - unique identifier of the entry
- */
- void erase(std::string entryId);
-
- /**
- * @brief Deletes all versions except for the current one
- */
- void deleteAll();
-
- /** @brief Creates an active association to the
- * newly active software image
- *
- * @param[in] path - The path to create the association to.
- */
- void createActiveAssociation(const std::string& path);
-
- /** @brief Removes an active association to the software image
- *
- * @param[in] path - The path to remove the association from.
- */
- void removeActiveAssociation(const std::string& path);
-
- /** @brief Determine if the given priority is the lowest
- *
- * @param[in] value - The priority that needs to be checked.
- *
- * @return boolean corresponding to whether the given
- * priority is lowest.
- */
- bool isLowestPriority(uint8_t value);
-
- /**
- * @brief Updates the U-Boot variables to point to the requested
- * versionId, so that the systems boots from this version on
- * the next reboot.
- *
- * @param[in] versionId - The version to point the system to boot from.
- */
- void updateUbootEnvVars(const std::string& versionId);
-
- /**
- * @brief Updates the uboot variables to point to BMC version with lowest
- * priority, so that the system boots from this version on the
- * next boot.
- */
- void resetUbootEnvVars();
-
- /** @brief Brings the total number of active BMC versions to
- * ACTIVE_BMC_MAX_ALLOWED -1. This function is intended to be
- * run before activating a new BMC version. If this function
- * needs to delete any BMC version(s) it will delete the
- * version(s) with the highest priority, skipping the
- * functional BMC version.
- */
- void freeSpace();
-
- private:
- /** @brief Callback function for Software.Version match.
- * @details Creates an Activation D-Bus object.
- *
- * @param[in] msg - Data associated with subscribed signal
- */
- void createActivation(sdbusplus::message::message& msg);
-
- /**
- * @brief Validates the presence of SquashFS image in the image dir.
- *
- * @param[in] filePath - The path to the image dir.
- * @param[out] result - ActivationStatus Enum.
- * ready if validation was successful.
- * invalid if validation fail.
- * active if image is the current version.
- *
- */
- ActivationStatus validateSquashFSImage(const std::string& filePath);
-
- /** @brief BMC factory reset - marks the read-write partition for
- * recreation upon reboot. */
- void reset() override;
-
- /**
- * @brief Enables field mode, if value=true.
- *
- * @param[in] value - If true, enables field mode.
- * @param[out] result - Returns the current state of field mode.
- *
- */
- bool fieldModeEnabled(bool value) override;
-
- /** @brief Sets the BMC inventory item path under
- * /xyz/openbmc_project/inventory/system/chassis/. */
- void setBMCInventoryPath();
-
- /** @brief The path to the BMC inventory item. */
- std::string bmcInventoryPath;
-
- /** @brief Restores field mode status on reboot. */
- void restoreFieldModeStatus();
-
- /** @brief Creates a functional association to the
- * "running" BMC software image
- *
- * @param[in] path - The path to create the association to.
- */
- void createFunctionalAssociation(const std::string& path);
-
- /** @brief Persistent sdbusplus D-Bus bus connection. */
- sdbusplus::bus::bus& bus;
-
- /** @brief Persistent map of Activation D-Bus objects and their
- * version id */
- std::map<std::string, std::unique_ptr<Activation>> activations;
-
- /** @brief Persistent map of Version D-Bus objects and their
- * version id */
- std::map<std::string, std::unique_ptr<VersionClass>> versions;
-
- /** @brief sdbusplus signal match for Software.Version */
- sdbusplus::bus::match_t versionMatch;
-
- /** @brief This entry's associations */
- AssociationList assocs = {};
-
- /** @brief Clears read only partition for
- * given Activation D-Bus object.
- *
- * @param[in] versionId - The version id.
- */
- void removeReadOnlyPartition(std::string versionId);
+ public:
+ /*
+ * @brief Types of Activation status for image validation.
+ */
+ enum class ActivationStatus
+ {
+ ready,
+ invalid,
+ active
+ };
+
+ /** @brief Constructs ItemUpdater
+ *
+ * @param[in] bus - The D-Bus bus object
+ */
+ ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
+ ItemUpdaterInherit(bus, path.c_str(), false), bus(bus),
+ versionMatch(bus,
+ MatchRules::interfacesAdded() +
+ MatchRules::path("/xyz/openbmc_project/software"),
+ std::bind(std::mem_fn(&ItemUpdater::createActivation),
+ this, std::placeholders::_1))
+ {
+ setBMCInventoryPath();
+ processBMCImage();
+ restoreFieldModeStatus();
+ emit_object_added();
+ };
+
+ /** @brief Sets the given priority free by incrementing
+ * any existing priority with the same value by 1
+ *
+ * @param[in] value - The priority that needs to be set free.
+ * @param[in] versionId - The Id of the version for which we
+ * are trying to free up the priority.
+ * @return None
+ */
+ void freePriority(uint8_t value, const std::string& versionId);
+
+ /**
+ * @brief Create and populate the active BMC Version.
+ */
+ void processBMCImage();
+
+ /**
+ * @brief Erase specified entry D-Bus object
+ * if Action property is not set to Active
+ *
+ * @param[in] entryId - unique identifier of the entry
+ */
+ void erase(std::string entryId);
+
+ /**
+ * @brief Deletes all versions except for the current one
+ */
+ void deleteAll();
+
+ /** @brief Creates an active association to the
+ * newly active software image
+ *
+ * @param[in] path - The path to create the association to.
+ */
+ void createActiveAssociation(const std::string& path);
+
+ /** @brief Removes an active association to the software image
+ *
+ * @param[in] path - The path to remove the association from.
+ */
+ void removeActiveAssociation(const std::string& path);
+
+ /** @brief Determine if the given priority is the lowest
+ *
+ * @param[in] value - The priority that needs to be checked.
+ *
+ * @return boolean corresponding to whether the given
+ * priority is lowest.
+ */
+ bool isLowestPriority(uint8_t value);
+
+ /**
+ * @brief Updates the U-Boot variables to point to the requested
+ * versionId, so that the systems boots from this version on
+ * the next reboot.
+ *
+ * @param[in] versionId - The version to point the system to boot from.
+ */
+ void updateUbootEnvVars(const std::string& versionId);
+
+ /**
+ * @brief Updates the uboot variables to point to BMC version with lowest
+ * priority, so that the system boots from this version on the
+ * next boot.
+ */
+ void resetUbootEnvVars();
+
+ /** @brief Brings the total number of active BMC versions to
+ * ACTIVE_BMC_MAX_ALLOWED -1. This function is intended to be
+ * run before activating a new BMC version. If this function
+ * needs to delete any BMC version(s) it will delete the
+ * version(s) with the highest priority, skipping the
+ * functional BMC version.
+ */
+ void freeSpace();
+
+ private:
+ /** @brief Callback function for Software.Version match.
+ * @details Creates an Activation D-Bus object.
+ *
+ * @param[in] msg - Data associated with subscribed signal
+ */
+ void createActivation(sdbusplus::message::message& msg);
+
+ /**
+ * @brief Validates the presence of SquashFS image in the image dir.
+ *
+ * @param[in] filePath - The path to the image dir.
+ * @param[out] result - ActivationStatus Enum.
+ * ready if validation was successful.
+ * invalid if validation fail.
+ * active if image is the current version.
+ *
+ */
+ ActivationStatus validateSquashFSImage(const std::string& filePath);
+
+ /** @brief BMC factory reset - marks the read-write partition for
+ * recreation upon reboot. */
+ void reset() override;
+
+ /**
+ * @brief Enables field mode, if value=true.
+ *
+ * @param[in] value - If true, enables field mode.
+ * @param[out] result - Returns the current state of field mode.
+ *
+ */
+ bool fieldModeEnabled(bool value) override;
+
+ /** @brief Sets the BMC inventory item path under
+ * /xyz/openbmc_project/inventory/system/chassis/. */
+ void setBMCInventoryPath();
+
+ /** @brief The path to the BMC inventory item. */
+ std::string bmcInventoryPath;
+
+ /** @brief Restores field mode status on reboot. */
+ void restoreFieldModeStatus();
+
+ /** @brief Creates a functional association to the
+ * "running" BMC software image
+ *
+ * @param[in] path - The path to create the association to.
+ */
+ void createFunctionalAssociation(const std::string& path);
+
+ /** @brief Persistent sdbusplus D-Bus bus connection. */
+ sdbusplus::bus::bus& bus;
+
+ /** @brief Persistent map of Activation D-Bus objects and their
+ * version id */
+ std::map<std::string, std::unique_ptr<Activation>> activations;
+
+ /** @brief Persistent map of Version D-Bus objects and their
+ * version id */
+ std::map<std::string, std::unique_ptr<VersionClass>> versions;
+
+ /** @brief sdbusplus signal match for Software.Version */
+ sdbusplus::bus::match_t versionMatch;
+
+ /** @brief This entry's associations */
+ AssociationList assocs = {};
+
+ /** @brief Clears read only partition for
+ * given Activation D-Bus object.
+ *
+ * @param[in] versionId - The version id.
+ */
+ void removeReadOnlyPartition(std::string versionId);
};
} // namespace updater
diff --git a/serialize.cpp b/serialize.cpp
index 5060c9a..b59ff46 100644
--- a/serialize.cpp
+++ b/serialize.cpp
@@ -29,12 +29,9 @@ void storeToFile(std::string versionId, uint8_t priority)
oarchive(cereal::make_nvp("priority", priority));
std::string serviceFile = "obmc-flash-bmc-setenv@" + versionId + "\\x3d" +
- std::to_string(priority) + ".service";
- auto method = bus.new_method_call(
- SYSTEMD_BUSNAME,
- SYSTEMD_PATH,
- SYSTEMD_INTERFACE,
- "StartUnit");
+ std::to_string(priority) + ".service";
+ auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "StartUnit");
method.append(serviceFile, "replace");
bus.call_noreply(method);
}
@@ -91,7 +88,9 @@ bool restoreFromFile(std::string versionId, uint8_t& priority)
}
}
}
- catch (const std::exception& e){}
+ catch (const std::exception& e)
+ {
+ }
return false;
}
diff --git a/test/utest.cpp b/test/utest.cpp
index f777742..ac0aa7c 100755
--- a/test/utest.cpp
+++ b/test/utest.cpp
@@ -11,28 +11,26 @@
using namespace phosphor::software::manager;
namespace fs = std::experimental::filesystem;
-
class VersionTest : public testing::Test
{
- protected:
+ protected:
+ virtual void SetUp()
+ {
+ char versionDir[] = "./versionXXXXXX";
+ _directory = mkdtemp(versionDir);
- virtual void SetUp()
+ if (_directory.empty())
{
- char versionDir[] = "./versionXXXXXX";
- _directory = mkdtemp(versionDir);
-
- if (_directory.empty())
- {
- throw std::bad_alloc();
- }
+ throw std::bad_alloc();
}
+ }
- virtual void TearDown()
- {
- fs::remove_all(_directory);
- }
+ virtual void TearDown()
+ {
+ fs::remove_all(_directory);
+ }
- std::string _directory;
+ std::string _directory;
};
/** @brief Make sure we correctly get the version and purpose from getValue()*/
@@ -63,10 +61,10 @@ TEST_F(VersionTest, TestGetId)
SHA512_Init(&ctx);
SHA512_Update(&ctx, version, strlen(version));
SHA512_Final(digest, &ctx);
- char mdString[SHA512_DIGEST_LENGTH*2+1];
+ char mdString[SHA512_DIGEST_LENGTH * 2 + 1];
for (int i = 0; i < SHA512_DIGEST_LENGTH; i++)
{
- snprintf(&mdString[i*2], 3, "%02x", (unsigned int)digest[i]);
+ snprintf(&mdString[i * 2], 3, "%02x", (unsigned int)digest[i]);
}
std::string hexId = std::string(mdString);
hexId = hexId.substr(0, 8);
diff --git a/version.cpp b/version.cpp
index 724ffea..3b1b0c9 100644
--- a/version.cpp
+++ b/version.cpp
@@ -31,15 +31,14 @@ std::string Version::getValue(const std::string& manifestFilePath,
{
log<level::ERR>("Error MANIFESTFilePath is empty");
elog<InvalidArgument>(
- Argument::ARGUMENT_NAME("manifestFilePath"),
- Argument::ARGUMENT_VALUE(manifestFilePath.c_str()));
+ Argument::ARGUMENT_NAME("manifestFilePath"),
+ Argument::ARGUMENT_VALUE(manifestFilePath.c_str()));
}
std::string value{};
std::ifstream efile;
std::string line;
- efile.exceptions(std::ifstream::failbit |
- std::ifstream::badbit |
+ efile.exceptions(std::ifstream::failbit | std::ifstream::badbit |
std::ifstream::eofbit);
// Too many GCC bugs (53984, 66145) to do this the right way...
@@ -79,10 +78,10 @@ std::string Version::getId(const std::string& version)
SHA512_Init(&ctx);
SHA512_Update(&ctx, version.c_str(), strlen(version.c_str()));
SHA512_Final(digest, &ctx);
- char mdString[SHA512_DIGEST_LENGTH*2+1];
+ char mdString[SHA512_DIGEST_LENGTH * 2 + 1];
for (int i = 0; i < SHA512_DIGEST_LENGTH; i++)
{
- snprintf(&mdString[i*2], 3, "%02x", (unsigned int)digest[i]);
+ snprintf(&mdString[i * 2], 3, "%02x", (unsigned int)digest[i]);
}
// Only need 8 hex digits.
diff --git a/version.hpp b/version.hpp
index b7efe44..75d9f8b 100644
--- a/version.hpp
+++ b/version.hpp
@@ -16,10 +16,10 @@ namespace manager
typedef std::function<void(std::string)> eraseFunc;
using VersionInherit = sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Software::server::Version,
- sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
+ sdbusplus::xyz::openbmc_project::Software::server::Version,
+ sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
using DeleteInherit = sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Object::server::Delete>;
+ sdbusplus::xyz::openbmc_project::Object::server::Delete>;
class Version;
class Delete;
@@ -31,44 +31,38 @@ class Delete;
*/
class Delete : public DeleteInherit
{
- public:
- /** @brief Constructs Delete.
- *
- * @param[in] bus - The D-Bus bus object
- * @param[in] path - The D-Bus object path
- * @param[in] parent - Parent object.
- */
- Delete(sdbusplus::bus::bus& bus,
- const std::string& path,
- Version& parent) :
- DeleteInherit(bus, path.c_str(), true),
- parent(parent),
- bus(bus),
- path(path)
- {
- std::vector<std::string> interfaces({interface});
- bus.emit_interfaces_added(path.c_str(), interfaces);
- }
-
- ~Delete()
- {
- std::vector<std::string> interfaces({interface});
- bus.emit_interfaces_removed(path.c_str(), interfaces);
- }
-
- /** @brief delete the D-Bus object. */
- void delete_() override;
-
- private:
-
- /** @brief Parent Object. */
- Version& parent;
-
- // TODO Remove once openbmc/openbmc#1975 is resolved
- static constexpr auto interface =
- "xyz.openbmc_project.Object.Delete";
- sdbusplus::bus::bus& bus;
- std::string path;
+ public:
+ /** @brief Constructs Delete.
+ *
+ * @param[in] bus - The D-Bus bus object
+ * @param[in] path - The D-Bus object path
+ * @param[in] parent - Parent object.
+ */
+ Delete(sdbusplus::bus::bus& bus, const std::string& path, Version& parent) :
+ DeleteInherit(bus, path.c_str(), true), parent(parent), bus(bus),
+ path(path)
+ {
+ std::vector<std::string> interfaces({interface});
+ bus.emit_interfaces_added(path.c_str(), interfaces);
+ }
+
+ ~Delete()
+ {
+ std::vector<std::string> interfaces({interface});
+ bus.emit_interfaces_removed(path.c_str(), interfaces);
+ }
+
+ /** @brief delete the D-Bus object. */
+ void delete_() override;
+
+ private:
+ /** @brief Parent Object. */
+ Version& parent;
+
+ // TODO Remove once openbmc/openbmc#1975 is resolved
+ static constexpr auto interface = "xyz.openbmc_project.Object.Delete";
+ sdbusplus::bus::bus& bus;
+ std::string path;
};
/** @class Version
@@ -78,82 +72,78 @@ class Delete : public DeleteInherit
*/
class Version : public VersionInherit
{
- public:
- /** @brief Constructs Version Software Manager
- *
- * @param[in] bus - The D-Bus bus object
- * @param[in] objPath - The D-Bus object path
- * @param[in] versionString - The version string
- * @param[in] versionPurpose - The version purpose
- * @param[in] filePath - The image filesystem path
- * @param[in] callback - The eraseFunc callback
- */
- Version(sdbusplus::bus::bus& bus,
- const std::string& objPath,
- const std::string& versionString,
- VersionPurpose versionPurpose,
- const std::string& filePath,
- eraseFunc callback) : VersionInherit(
- bus, (objPath).c_str(), true),
- versionStr(versionString)
- {
- // Bind erase method
- eraseCallback = callback;
- // Set properties.
- purpose(versionPurpose);
- version(versionString);
- path(filePath);
- // Emit deferred signal.
- emit_object_added();
- }
-
- /**
- * @brief Read the manifest file to get the value of the key.
- *
- * @return The value of the key.
- **/
- static std::string getValue(const std::string& manifestFilePath,
- std::string key);
-
- /**
- * @brief Calculate the version id from the version string.
- *
- * @details The version id is a unique 8 hexadecimal digit id
- * calculated from the version string.
- *
- * @param[in] version - The image's version string (e.g. v1.99.10-19).
- *
- * @return The id.
- */
- static std::string getId(const std::string& version);
-
- /**
- * @brief Get the active BMC version string.
- *
- * @param[in] releaseFilePath - The path to the file which contains
- * the release version string.
- *
- * @return The version string (e.g. v1.99.10-19).
- */
- static std::string getBMCVersion(const std::string& releaseFilePath);
-
- /* @brief Check if this version matches the currently running version
- *
- * @return - Returns true if this version matches the currently running
- * version.
- */
- bool isFunctional();
-
- /** @brief Persistent Delete D-Bus object */
- std::unique_ptr<Delete> deleteObject;
-
- /** @brief The parent's erase callback. */
- eraseFunc eraseCallback;
-
- private:
-
- /** @brief This Version's version string */
- const std::string versionStr;
+ public:
+ /** @brief Constructs Version Software Manager
+ *
+ * @param[in] bus - The D-Bus bus object
+ * @param[in] objPath - The D-Bus object path
+ * @param[in] versionString - The version string
+ * @param[in] versionPurpose - The version purpose
+ * @param[in] filePath - The image filesystem path
+ * @param[in] callback - The eraseFunc callback
+ */
+ Version(sdbusplus::bus::bus& bus, const std::string& objPath,
+ const std::string& versionString, VersionPurpose versionPurpose,
+ const std::string& filePath, eraseFunc callback) :
+ VersionInherit(bus, (objPath).c_str(), true),
+ versionStr(versionString)
+ {
+ // Bind erase method
+ eraseCallback = callback;
+ // Set properties.
+ purpose(versionPurpose);
+ version(versionString);
+ path(filePath);
+ // Emit deferred signal.
+ emit_object_added();
+ }
+
+ /**
+ * @brief Read the manifest file to get the value of the key.
+ *
+ * @return The value of the key.
+ **/
+ static std::string getValue(const std::string& manifestFilePath,
+ std::string key);
+
+ /**
+ * @brief Calculate the version id from the version string.
+ *
+ * @details The version id is a unique 8 hexadecimal digit id
+ * calculated from the version string.
+ *
+ * @param[in] version - The image's version string (e.g. v1.99.10-19).
+ *
+ * @return The id.
+ */
+ static std::string getId(const std::string& version);
+
+ /**
+ * @brief Get the active BMC version string.
+ *
+ * @param[in] releaseFilePath - The path to the file which contains
+ * the release version string.
+ *
+ * @return The version string (e.g. v1.99.10-19).
+ */
+ static std::string getBMCVersion(const std::string& releaseFilePath);
+
+ /* @brief Check if this version matches the currently running version
+ *
+ * @return - Returns true if this version matches the currently running
+ * version.
+ */
+ bool isFunctional();
+
+ /** @brief Persistent Delete D-Bus object */
+ std::unique_ptr<Delete> deleteObject;
+
+ /** @brief The parent's erase callback. */
+ eraseFunc eraseCallback;
+
+ private:
+ /** @brief This Version's version string */
+ const std::string versionStr;
};
} // namespace manager
diff --git a/watch.cpp b/watch.cpp
index c7c3653..a84c5ef 100644
--- a/watch.cpp
+++ b/watch.cpp
@@ -21,9 +21,8 @@ using namespace phosphor::logging;
using namespace std::string_literals;
namespace fs = std::experimental::filesystem;
-Watch::Watch(sd_event* loop,
- std::function<int(std::string&)> imageCallback) : imageCallback(
- imageCallback)
+Watch::Watch(sd_event* loop, std::function<int(std::string&)> imageCallback) :
+ imageCallback(imageCallback)
{
// Check if IMAGE DIR exists.
fs::path imgDirPath(IMG_UPLOAD_DIR);
@@ -38,8 +37,8 @@ Watch::Watch(sd_event* loop,
// Store a copy of errno, because the string creation below will
// invalidate errno due to one more system calls.
auto error = errno;
- throw std::runtime_error(
- "inotify_init1 failed, errno="s + std::strerror(error));
+ throw std::runtime_error("inotify_init1 failed, errno="s +
+ std::strerror(error));
}
wd = inotify_add_watch(fd, IMG_UPLOAD_DIR, IN_CLOSE_WRITE);
@@ -47,20 +46,15 @@ Watch::Watch(sd_event* loop,
{
auto error = errno;
close(fd);
- throw std::runtime_error(
- "inotify_add_watch failed, errno="s + std::strerror(error));
+ throw std::runtime_error("inotify_add_watch failed, errno="s +
+ std::strerror(error));
}
- auto rc = sd_event_add_io(loop,
- nullptr,
- fd,
- EPOLLIN,
- callback,
- this);
+ auto rc = sd_event_add_io(loop, nullptr, fd, EPOLLIN, callback, this);
if (0 > rc)
{
- throw std::runtime_error(
- "failed to add to event loop, rc="s + std::strerror(-rc));
+ throw std::runtime_error("failed to add to event loop, rc="s +
+ std::strerror(-rc));
}
}
@@ -73,9 +67,7 @@ Watch::~Watch()
}
}
-int Watch::callback(sd_event_source* s,
- int fd,
- uint32_t revents,
+int Watch::callback(sd_event_source* s, int fd, uint32_t revents,
void* userdata)
{
if (!(revents & EPOLLIN))
@@ -89,8 +81,8 @@ int Watch::callback(sd_event_source* s,
if (0 > bytes)
{
auto error = errno;
- throw std::runtime_error(
- "failed to read inotify event, errno="s + std::strerror(error));
+ throw std::runtime_error("failed to read inotify event, errno="s +
+ std::strerror(error));
}
auto offset = 0;
@@ -106,7 +98,6 @@ int Watch::callback(sd_event_source* s,
log<level::ERR>("Error processing image",
entry("IMAGE=%s", tarballPath.c_str()));
}
-
}
offset += offsetof(inotify_event, name) + event->len;
diff --git a/watch.hpp b/watch.hpp
index f7eb695..451f1d6 100644
--- a/watch.hpp
+++ b/watch.hpp
@@ -19,47 +19,44 @@ namespace manager
*/
class Watch
{
- public:
- /** @brief ctor - hook inotify watch with sd-event
- *
- * @param[in] loop - sd-event object
- * @param[in] imageCallback - The callback function for processing
- * the image
- */
- Watch(sd_event* loop,
- std::function<int(std::string&)> imageCallback);
+ public:
+ /** @brief ctor - hook inotify watch with sd-event
+ *
+ * @param[in] loop - sd-event object
+ * @param[in] imageCallback - The callback function for processing
+ * the image
+ */
+ Watch(sd_event* loop, std::function<int(std::string&)> imageCallback);
- Watch(const Watch&) = delete;
- Watch& operator=(const Watch&) = delete;
- Watch(Watch&&) = delete;
- Watch& operator=(Watch&&) = delete;
+ Watch(const Watch&) = delete;
+ Watch& operator=(const Watch&) = delete;
+ Watch(Watch&&) = delete;
+ Watch& operator=(Watch&&) = delete;
- /** @brief dtor - remove inotify watch and close fd's
- */
- ~Watch();
+ /** @brief dtor - remove inotify watch and close fd's
+ */
+ ~Watch();
- private:
- /** @brief sd-event callback
- *
- * @param[in] s - event source, floating (unused) in our case
- * @param[in] fd - inotify fd
- * @param[in] revents - events that matched for fd
- * @param[in] userdata - pointer to Watch object
- * @returns 0 on success, -1 on fail
- */
- static int callback(sd_event_source* s,
- int fd,
- uint32_t revents,
- void* userdata);
+ private:
+ /** @brief sd-event callback
+ *
+ * @param[in] s - event source, floating (unused) in our case
+ * @param[in] fd - inotify fd
+ * @param[in] revents - events that matched for fd
+ * @param[in] userdata - pointer to Watch object
+ * @returns 0 on success, -1 on fail
+ */
+ static int callback(sd_event_source* s, int fd, uint32_t revents,
+ void* userdata);
- /** @brief image upload directory watch descriptor */
- int wd = -1;
+ /** @brief image upload directory watch descriptor */
+ int wd = -1;
- /** @brief inotify file descriptor */
- int fd = -1;
+ /** @brief inotify file descriptor */
+ int fd = -1;
- /** @brief The callback function for processing the image. */
- std::function<int(std::string&)> imageCallback;
+ /** @brief The callback function for processing the image. */
+ std::function<int(std::string&)> imageCallback;
};
} // namespace manager
OpenPOWER on IntegriCloud