Skip to content

Commit

Permalink
When teamd feature state is disabled the Netdevice created by teamd w…
Browse files Browse the repository at this point in the history
…ere (sonic-net#1450)

not cleaned up.

Issue was seen in Multi-asic platform and seems to be timing issue where
SIGTERM send via kill systemcall of teammgrd to teamd was not cleaning
all teamd process.

Sp fix is Instead  of sending explicit SIGTERM to teamd we are calling
teamd -k. Using this teamd itself generate SIGTERM and handle the
processing.

Signed-off-by: Abhishek Dosi <[email protected]>
  • Loading branch information
abdosi authored Sep 28, 2020
1 parent 6aa97ce commit 76e2251
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 73 deletions.
71 changes: 3 additions & 68 deletions cfgmgr/teammgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <fstream>
#include <thread>

#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <signal.h>

#define PID_FILE_PATH "/var/run/teamd/"

using namespace std;
using namespace swss;
Expand Down Expand Up @@ -115,75 +113,14 @@ void TeamMgr::doTask(Consumer &consumer)
}


pid_t TeamMgr::getTeamPid(const string &alias)
void TeamMgr::cleanTeamProcesses()
{
SWSS_LOG_ENTER();
pid_t pid = 0;

string file = string(PID_FILE_PATH) + alias + string(".pid");
ifstream infile(file);
if (!infile.is_open())
{
SWSS_LOG_WARN("The LAG PID file: %s is not readable", file.c_str());
return 0;
}

string line;
getline(infile, line);
if (line.empty())
{
SWSS_LOG_WARN("The LAG PID file: %s is empty", file.c_str());
}
else
{
/*Store the PID value */
pid = stoi(line, nullptr, 10);
}

/* Close the file and return */
infile.close();

return pid;
}


void TeamMgr::addLagPid(const string &alias)
{
SWSS_LOG_ENTER();
m_lagPIDList[alias] = getTeamPid(alias);
}

void TeamMgr::removeLagPid(const string &alias)
{
SWSS_LOG_ENTER();
m_lagPIDList.erase(alias);
}

void TeamMgr::cleanTeamProcesses(int signo)
{
pid_t pid = 0;

SWSS_LOG_ENTER();
SWSS_LOG_NOTICE("Cleaning up LAGs during shutdown...");
for (const auto& it: m_lagList)
{
pid = m_lagPIDList[it];
if(!pid) {
SWSS_LOG_WARN("Invalid PID found for LaG %s ", it.c_str());

/* Try to get the PID again */
pid = getTeamPid(it);
}

if(pid > 0)
{
SWSS_LOG_INFO("Sending TERM Signal to (PID: %d) for LaG %s ", pid, it.c_str());
kill(pid, signo);
}
else
{
SWSS_LOG_ERROR("Can't send TERM signal to LAG %s. PID wasn't found", it.c_str());
}
//This will call team -k kill -t <teamdevicename> which internally send SIGTERM
removeLag(it);
}

return;
Expand Down Expand Up @@ -252,7 +189,6 @@ void TeamMgr::doLagTask(Consumer &consumer)
}

m_lagList.insert(alias);
addLagPid(alias);
}

setLagAdminStatus(alias, admin_status);
Expand All @@ -269,7 +205,6 @@ void TeamMgr::doLagTask(Consumer &consumer)
{
removeLag(alias);
m_lagList.erase(alias);
removeLagPid(alias);
}
}

Expand Down
5 changes: 1 addition & 4 deletions cfgmgr/teammgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TeamMgr : public Orch
const std::vector<TableConnector> &tables);

using Orch::doTask;
void cleanTeamProcesses(int signo);
void cleanTeamProcesses();

private:
Table m_cfgMetadataTable; // To retrieve MAC address
Expand Down Expand Up @@ -50,9 +50,6 @@ class TeamMgr : public Orch
bool setLagMtu(const std::string &alias, const std::string &mtu);
bool setLagLearnMode(const std::string &alias, const std::string &learn_mode);

pid_t getTeamPid(const std::string &alias);
void addLagPid(const std::string &alias);
void removeLagPid(const std::string &alias);

bool isPortEnslaved(const std::string &);
bool findPortMaster(std::string &, const std::string &);
Expand Down
2 changes: 1 addition & 1 deletion cfgmgr/teammgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int main(int argc, char **argv)
auto *c = (Executor *)sel;
c->execute();
}
teammgr.cleanTeamProcesses(SIGTERM);
teammgr.cleanTeamProcesses();
SWSS_LOG_NOTICE("Exiting");
}
catch (const exception &e)
Expand Down

0 comments on commit 76e2251

Please sign in to comment.