item_updater: Ignore base version when trying to free up priority.
- There is a bug in our code where a user can try to allocate the
existing priority of a version to itself and this would cause
all subsequent priorities to be incremented by 2 instead of 1.
- By checking the base versionId we can skip the operation to free
the priority of the base version since it will be reassigned.
Resolves openbmc/openbmc#2075
Change-Id: Ice21d701bb2e964c5734273f4e8a3821b96f4830
Signed-off-by: Saqib Khan <khansa@us.ibm.com>
diff --git a/activation.cpp b/activation.cpp
index 56b1b67..fd54ccd 100755
--- a/activation.cpp
+++ b/activation.cpp
@@ -212,7 +212,7 @@
uint8_t RedundancyPriority::priority(uint8_t value)
{
- parent.parent.freePriority(value);
+ parent.parent.freePriority(value, parent.versionId);
if(parent.parent.isLowestPriority(value))
{
diff --git a/item_updater.cpp b/item_updater.cpp
index ee4aa0a..d022c96 100755
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -297,14 +297,15 @@
return;
}
-void ItemUpdater::freePriority(uint8_t value)
+void ItemUpdater::freePriority(uint8_t value, const std::string& versionId)
{
//TODO openbmc/openbmc#1896 Improve the performance of this function
for (const auto& intf : activations)
{
if(intf.second->redundancyPriority)
{
- if (intf.second->redundancyPriority.get()->priority() == value)
+ if (intf.second->redundancyPriority.get()->priority() == value &&
+ intf.second->versionId != versionId)
{
intf.second->redundancyPriority.get()->priority(value+1);
}
diff --git a/item_updater.hpp b/item_updater.hpp
index 934ec3c..2f3b1ea 100755
--- a/item_updater.hpp
+++ b/item_updater.hpp
@@ -46,10 +46,11 @@
* 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);
+ void freePriority(uint8_t value, const std::string& versionId);
/** @brief Determine is the given priority is the lowest
*