From 76e22516bffe45d577ab9cce4f5d96687140fe75 Mon Sep 17 00:00:00 2001 From: abdosi <58047199+abdosi@users.noreply.github.com> Date: Mon, 28 Sep 2020 14:06:45 -0700 Subject: [PATCH] When teamd feature state is disabled the Netdevice created by teamd were (#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 --- cfgmgr/teammgr.cpp | 71 ++------------------------------------------- cfgmgr/teammgr.h | 5 +--- cfgmgr/teammgrd.cpp | 2 +- 3 files changed, 5 insertions(+), 73 deletions(-) diff --git a/cfgmgr/teammgr.cpp b/cfgmgr/teammgr.cpp index 4266688e59e4..cdff7013a072 100644 --- a/cfgmgr/teammgr.cpp +++ b/cfgmgr/teammgr.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include @@ -18,7 +17,6 @@ #include #include -#define PID_FILE_PATH "/var/run/teamd/" using namespace std; using namespace swss; @@ -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 which internally send SIGTERM + removeLag(it); } return; @@ -252,7 +189,6 @@ void TeamMgr::doLagTask(Consumer &consumer) } m_lagList.insert(alias); - addLagPid(alias); } setLagAdminStatus(alias, admin_status); @@ -269,7 +205,6 @@ void TeamMgr::doLagTask(Consumer &consumer) { removeLag(alias); m_lagList.erase(alias); - removeLagPid(alias); } } diff --git a/cfgmgr/teammgr.h b/cfgmgr/teammgr.h index 9003d25d54ee..0c0ff62579a2 100644 --- a/cfgmgr/teammgr.h +++ b/cfgmgr/teammgr.h @@ -18,7 +18,7 @@ class TeamMgr : public Orch const std::vector &tables); using Orch::doTask; - void cleanTeamProcesses(int signo); + void cleanTeamProcesses(); private: Table m_cfgMetadataTable; // To retrieve MAC address @@ -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 &); diff --git a/cfgmgr/teammgrd.cpp b/cfgmgr/teammgrd.cpp index 9a97a3d50250..1ff2ed760e51 100644 --- a/cfgmgr/teammgrd.cpp +++ b/cfgmgr/teammgrd.cpp @@ -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)