Skip to content

Commit 76e2251

Browse files
authored
When teamd feature state is disabled the Netdevice created by teamd were (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 <abdosi@microsoft.com>
1 parent 6aa97ce commit 76e2251

File tree

3 files changed

+5
-73
lines changed

3 files changed

+5
-73
lines changed

cfgmgr/teammgr.cpp

+3-68
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010
#include <iostream>
1111
#include <fstream>
1212
#include <sstream>
13-
#include <fstream>
1413
#include <thread>
1514

1615
#include <net/if.h>
1716
#include <sys/ioctl.h>
1817
#include <sys/stat.h>
1918
#include <signal.h>
2019

21-
#define PID_FILE_PATH "/var/run/teamd/"
2220

2321
using namespace std;
2422
using namespace swss;
@@ -115,75 +113,14 @@ void TeamMgr::doTask(Consumer &consumer)
115113
}
116114

117115

118-
pid_t TeamMgr::getTeamPid(const string &alias)
116+
void TeamMgr::cleanTeamProcesses()
119117
{
120-
SWSS_LOG_ENTER();
121-
pid_t pid = 0;
122-
123-
string file = string(PID_FILE_PATH) + alias + string(".pid");
124-
ifstream infile(file);
125-
if (!infile.is_open())
126-
{
127-
SWSS_LOG_WARN("The LAG PID file: %s is not readable", file.c_str());
128-
return 0;
129-
}
130-
131-
string line;
132-
getline(infile, line);
133-
if (line.empty())
134-
{
135-
SWSS_LOG_WARN("The LAG PID file: %s is empty", file.c_str());
136-
}
137-
else
138-
{
139-
/*Store the PID value */
140-
pid = stoi(line, nullptr, 10);
141-
}
142-
143-
/* Close the file and return */
144-
infile.close();
145-
146-
return pid;
147-
}
148-
149-
150-
void TeamMgr::addLagPid(const string &alias)
151-
{
152-
SWSS_LOG_ENTER();
153-
m_lagPIDList[alias] = getTeamPid(alias);
154-
}
155-
156-
void TeamMgr::removeLagPid(const string &alias)
157-
{
158-
SWSS_LOG_ENTER();
159-
m_lagPIDList.erase(alias);
160-
}
161-
162-
void TeamMgr::cleanTeamProcesses(int signo)
163-
{
164-
pid_t pid = 0;
165-
166118
SWSS_LOG_ENTER();
167119
SWSS_LOG_NOTICE("Cleaning up LAGs during shutdown...");
168120
for (const auto& it: m_lagList)
169121
{
170-
pid = m_lagPIDList[it];
171-
if(!pid) {
172-
SWSS_LOG_WARN("Invalid PID found for LaG %s ", it.c_str());
173-
174-
/* Try to get the PID again */
175-
pid = getTeamPid(it);
176-
}
177-
178-
if(pid > 0)
179-
{
180-
SWSS_LOG_INFO("Sending TERM Signal to (PID: %d) for LaG %s ", pid, it.c_str());
181-
kill(pid, signo);
182-
}
183-
else
184-
{
185-
SWSS_LOG_ERROR("Can't send TERM signal to LAG %s. PID wasn't found", it.c_str());
186-
}
122+
//This will call team -k kill -t <teamdevicename> which internally send SIGTERM
123+
removeLag(it);
187124
}
188125

189126
return;
@@ -252,7 +189,6 @@ void TeamMgr::doLagTask(Consumer &consumer)
252189
}
253190

254191
m_lagList.insert(alias);
255-
addLagPid(alias);
256192
}
257193

258194
setLagAdminStatus(alias, admin_status);
@@ -269,7 +205,6 @@ void TeamMgr::doLagTask(Consumer &consumer)
269205
{
270206
removeLag(alias);
271207
m_lagList.erase(alias);
272-
removeLagPid(alias);
273208
}
274209
}
275210

cfgmgr/teammgr.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TeamMgr : public Orch
1818
const std::vector<TableConnector> &tables);
1919

2020
using Orch::doTask;
21-
void cleanTeamProcesses(int signo);
21+
void cleanTeamProcesses();
2222

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

53-
pid_t getTeamPid(const std::string &alias);
54-
void addLagPid(const std::string &alias);
55-
void removeLagPid(const std::string &alias);
5653

5754
bool isPortEnslaved(const std::string &);
5855
bool findPortMaster(std::string &, const std::string &);

cfgmgr/teammgrd.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int main(int argc, char **argv)
8585
auto *c = (Executor *)sel;
8686
c->execute();
8787
}
88-
teammgr.cleanTeamProcesses(SIGTERM);
88+
teammgr.cleanTeamProcesses();
8989
SWSS_LOG_NOTICE("Exiting");
9090
}
9191
catch (const exception &e)

0 commit comments

Comments
 (0)