From de10bbfe7ad9200dfb6af51cab5146309bb4a665 Mon Sep 17 00:00:00 2001 From: Prabhu Sreenivasan <45380242+PrabhuSreenivasan@users.noreply.github.com> Date: Mon, 15 Feb 2021 23:39:37 +0530 Subject: [PATCH] fixed unsupported resource issue (#1641) Fix Azure/sonic-buildimage#6563 **What I did** Instead of erasing unsupported resource from m_resourcesMap, mark it as unsupported. **Why I did it** Erasing an entry while iterating using range based iterator makes the iterator invalid. Also removing a resource from the m_resourcesMap impacts cross access while iterating other maps (eg crmUsedCntsTableMap). **How I verified it** Added a new unsupported resource for testing and verified the logs. --- orchagent/crmorch.cpp | 10 ++++++++-- orchagent/crmorch.h | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/orchagent/crmorch.cpp b/orchagent/crmorch.cpp index d40ca195a2..659d35fb72 100644 --- a/orchagent/crmorch.cpp +++ b/orchagent/crmorch.cpp @@ -436,6 +436,12 @@ void CrmOrch::getResAvailableCounters() for (auto &res : m_resourcesMap) { + // ignore unsupported resources + if (res.second.resStatus != CrmResourceStatus::CRM_RES_SUPPORTED) + { + continue; + } + sai_attribute_t attr; attr.id = crmResSaiAvailAttrMap.at(res.first); @@ -462,8 +468,8 @@ void CrmOrch::getResAvailableCounters() SAI_STATUS_IS_ATTR_NOT_SUPPORTED(status) || SAI_STATUS_IS_ATTR_NOT_IMPLEMENTED(status)) { - // remove unsupported resources from map - m_resourcesMap.erase(res.first); + // mark unsupported resources + res.second.resStatus = CrmResourceStatus::CRM_RES_NOT_SUPPORTED; SWSS_LOG_NOTICE("Switch attribute %u not supported", attr.id); break; } diff --git a/orchagent/crmorch.h b/orchagent/crmorch.h index 21d039396c..7c093ffb24 100644 --- a/orchagent/crmorch.h +++ b/orchagent/crmorch.h @@ -37,6 +37,12 @@ enum class CrmThresholdType CRM_FREE, }; +enum class CrmResourceStatus +{ + CRM_RES_SUPPORTED, + CRM_RES_NOT_SUPPORTED, +}; + class CrmOrch : public Orch { public: @@ -77,6 +83,7 @@ class CrmOrch : public Orch std::map countersMap; uint32_t exceededLogCounter = 0; + CrmResourceStatus resStatus = CrmResourceStatus::CRM_RES_SUPPORTED; }; std::chrono::seconds m_pollingInterval;