Skip to content

Commit

Permalink
fixed unsupported resource issue (sonic-net#1641)
Browse files Browse the repository at this point in the history
Fix sonic-net/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.
  • Loading branch information
PrabhuSreenivasan authored and raphaelt-nvidia committed Oct 5, 2021
1 parent d927d04 commit de10bbf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions orchagent/crmorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}
Expand Down
7 changes: 7 additions & 0 deletions orchagent/crmorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ enum class CrmThresholdType
CRM_FREE,
};

enum class CrmResourceStatus
{
CRM_RES_SUPPORTED,
CRM_RES_NOT_SUPPORTED,
};

class CrmOrch : public Orch
{
public:
Expand Down Expand Up @@ -77,6 +83,7 @@ class CrmOrch : public Orch
std::map<std::string, CrmResourceCounter> countersMap;

uint32_t exceededLogCounter = 0;
CrmResourceStatus resStatus = CrmResourceStatus::CRM_RES_SUPPORTED;
};

std::chrono::seconds m_pollingInterval;
Expand Down

0 comments on commit de10bbf

Please sign in to comment.