diff options
-rwxr-xr-x | activation.cpp | 1 | ||||
-rwxr-xr-x | activation.hpp | 6 | ||||
-rwxr-xr-x | configure.ac | 4 | ||||
-rwxr-xr-x | item_updater.cpp | 27 | ||||
-rwxr-xr-x | item_updater.hpp | 5 |
5 files changed, 43 insertions, 0 deletions
diff --git a/activation.cpp b/activation.cpp index 55ce08ee9..3f16b7b15 100755 --- a/activation.cpp +++ b/activation.cpp @@ -115,6 +115,7 @@ auto Activation::activation(Activations value) -> if (value == softwareServer::Activation::Activations::Activating) { + parent.freeSpace(); softwareServer::Activation::activation(value); if (squashfsLoaded == false && rwVolumesCreated == false) diff --git a/activation.hpp b/activation.hpp index 12e4f461c..89083372b 100755 --- a/activation.hpp +++ b/activation.hpp @@ -211,6 +211,12 @@ class Activation : public ActivationInherit emit_object_added(); } + /** @brief Activation property get function + * + * @returns One of Activation::Activations + */ + using ActivationInherit::activation; + /** @brief Overloaded Activation property setter function * * @param[in] value - One of Activation::Activations diff --git a/configure.ac b/configure.ac index 48d359a4a..8abd1b575 100755 --- a/configure.ac +++ b/configure.ac @@ -99,5 +99,9 @@ AC_DEFINE(PNOR_RW_ACTIVE_PATH, "/var/lib/phosphor-software-manager/pnor/rw", AC_DEFINE(PNOR_PRSV_ACTIVE_PATH, "/var/lib/phosphor-software-manager/pnor/prsv", [Path to the active preserved pnor partitions]) +AC_ARG_VAR(ACTIVE_PNOR_MAX_ALLOWED, [The maximum allowed active pnor versions]) +AS_IF([test "x$ACTIVE_PNOR_MAX_ALLOWED" == "x"], [ACTIVE_PNOR_MAX_ALLOWED=2]) +AC_DEFINE_UNQUOTED([ACTIVE_PNOR_MAX_ALLOWED], [$ACTIVE_PNOR_MAX_ALLOWED], [The maximum allowed active pnor versions]) + AC_CONFIG_FILES([Makefile test/Makefile]) AC_OUTPUT diff --git a/item_updater.cpp b/item_updater.cpp index c6726d37b..dd313a8c6 100755 --- a/item_updater.cpp +++ b/item_updater.cpp @@ -355,6 +355,33 @@ void ItemUpdater::erase(std::string entryId) activations.erase(entryId); } +// TODO: openbmc/openbmc#1402 Monitor flash usage +void ItemUpdater::freeSpace() +{ + std::size_t count = 0; + decltype(activations.begin()->second->redundancyPriority.get()->priority()) + highestPriority = 0; + decltype(activations.begin()->second->versionId) highestPriorityVersion; + for (const auto& iter : activations) + { + if (iter.second.get()->activation() == server::Activation::Activations::Active) + { + count++; + if (iter.second->redundancyPriority.get()->priority() > highestPriority) + { + highestPriority = iter.second->redundancyPriority.get()->priority(); + highestPriorityVersion = iter.second->versionId; + } + } + } + // Remove the pnor version with highest priority since the PNOR + // can't hold more than 2 versions. + if (count >= ACTIVE_PNOR_MAX_ALLOWED) + { + erase(highestPriorityVersion); + } +} + } // namespace updater } // namespace software } // namespace openpower diff --git a/item_updater.hpp b/item_updater.hpp index 2f3b1ea6d..a9bc8f473 100755 --- a/item_updater.hpp +++ b/item_updater.hpp @@ -74,6 +74,11 @@ class ItemUpdater : public ItemUpdaterInherit */ void erase(std::string entryId); + /** @brief Deletes the active pnor version with highest priority + if the total number of volume exceeds the threshold. + */ + void freeSpace(); + private: /** @brief Callback function for Software.Version match. * @details Creates an Activation dbus object. |