Host updater: Add function to delete all versions

As a part of openbmc/openbmc#2264, implements a DeleteAll for all
non-functional host versions in the host updater.

Change-Id: I2943df248463ba8b4537096cf08f902d758c24a0
Signed-off-by: Michael Tritz <mtritz@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index d0a3562..261b9d6 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -459,6 +459,34 @@
     activations.erase(entryId);
 }
 
+void ItemUpdater::deleteAll()
+{
+    std::vector<std::string> deletableActivations;
+
+    for (const auto& activationIt : activations)
+    {
+        if (!isVersionFunctional(activationIt.first))
+        {
+            deletableActivations.push_back(activationIt.first);
+        }
+    }
+
+    for (const auto& deletableIt : deletableActivations)
+    {
+        ItemUpdater::erase(deletableIt);
+    }
+
+    // Remove any remaining pnor-ro- or pnor-rw- volumes that do not match
+    // the current version.
+    auto method = bus.new_method_call(
+            SYSTEMD_BUSNAME,
+            SYSTEMD_PATH,
+            SYSTEMD_INTERFACE,
+            "StartUnit");
+    method.append("obmc-flash-bios-cleanup.service", "replace");
+    bus.call_noreply(method);
+}
+
 // TODO: openbmc/openbmc#1402 Monitor flash usage
 void ItemUpdater::freeSpace()
 {
diff --git a/item_updater.hpp b/item_updater.hpp
index 5d2a15e..06e65a0 100755
--- a/item_updater.hpp
+++ b/item_updater.hpp
@@ -5,6 +5,7 @@
 #include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
 #include "version.hpp"
 #include "org/openbmc/Associations/server.hpp"
+#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
 
 namespace openpower
 {
@@ -15,7 +16,8 @@
 
 using ItemUpdaterInherit = sdbusplus::server::object::object<
     sdbusplus::xyz::openbmc_project::Common::server::FactoryReset,
-    sdbusplus::org::openbmc::server::Associations>;
+    sdbusplus::org::openbmc::server::Associations,
+    sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
 namespace MatchRules = sdbusplus::bus::match::rules;
 
 using AssociationList =
@@ -79,6 +81,11 @@
          */
         void erase(std::string entryId);
 
+        /**
+         * @brief Erases any non-active pnor versions.
+         */
+        void deleteAll();
+
         /** @brief Deletes the active pnor version with highest priority
                    if the total number of volume exceeds the threshold.
          */