Skip to content

Commit

Permalink
Fix tsan error in droplog
Browse files Browse the repository at this point in the history
Separate delete call.
Add some more safeguards.

Signed-off-by: Kiran Shastri <shastrinator@gmail.com>
(cherry picked from commit 1f5032f)
  • Loading branch information
shastrinator committed Dec 21, 2020
1 parent 0bdfd79 commit d1e85e0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 17 deletions.
30 changes: 20 additions & 10 deletions agent-ovs/lib/ExtraConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,6 @@ void ExtraConfigManager::packetDropPruneConfigUpdated(std::shared_ptr<PacketDrop
Mutator mutator(framework, "policyelement");
optional<shared_ptr<modelgbp::policy::Universe>> polUni =
modelgbp::policy::Universe::resolve(framework);
if(dropPrune->removed) {
opflex::modb::URI dropPruneURI =
opflex::modb::URIBuilder(polUni.get()->getURI())
.addElement("ObserverDropPruneConfig").addElement(dropPrune->filterName).build();
DropPruneConfig::remove(framework, dropPruneURI);
mutator.commit();
dropPruneMap.erase(dropPrune->filterName);
notifyPacketDropPruneConfigListeners(dropPrune->filterName);
return;
}
shared_ptr<DropPruneConfig> dropPruneCfg =
polUni.get()->addObserverDropPruneConfig(dropPrune->filterName);
dropPruneCfg->unsetSrcAddress();
Expand Down Expand Up @@ -238,17 +228,37 @@ void ExtraConfigManager::packetDropPruneConfigUpdated(std::shared_ptr<PacketDrop
dropPruneCfg->setDstPort(dropPrune->dport.get());
}
mutator.commit();
unique_lock<mutex> guard(prune_mutex);
dropPruneMap[dropPrune->filterName] = dropPrune;
guard.unlock();
notifyPacketDropPruneConfigListeners(dropPrune->filterName);
}

void ExtraConfigManager::packetDropPruneConfigDeleted(const std::string &filterName) {
using modelgbp::observer::DropPruneConfig;
Mutator mutator(framework, "policyelement");
optional<shared_ptr<modelgbp::policy::Universe>> polUni =
modelgbp::policy::Universe::resolve(framework);
opflex::modb::URI dropPruneURI =
opflex::modb::URIBuilder(polUni.get()->getURI())
.addElement("ObserverDropPruneConfig").addElement(filterName).build();
DropPruneConfig::remove(framework, dropPruneURI);
mutator.commit();
unique_lock<mutex> guard(prune_mutex);
dropPruneMap.erase(filterName);
guard.unlock();
notifyPacketDropPruneConfigListeners(filterName);
}

bool ExtraConfigManager::getPacketDropPruneSpec(const std::string &pruneFilter, std::shared_ptr<PacketDropLogPruneSpec> &pruneSpec) {
bool ret = false;
unique_lock<mutex> guard(prune_mutex);
auto it= dropPruneMap.find(pruneFilter);
if(it != dropPruneMap.end()) {
pruneSpec = it->second;
ret = true;
}
guard.unlock();
return ret;
}

Expand Down
8 changes: 2 additions & 6 deletions agent-ovs/lib/FSPacketDropLogConfigSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ void FSPacketDropLogConfigSource::updated(const fs::path& filePath) {
/*Notify removed*/
if(dropPruneCfgSet) {
for(auto itr: *dropPruneCfgSet) {
std::shared_ptr<PacketDropLogPruneSpec> pruneSpec(new PacketDropLogPruneSpec(itr));
pruneSpec->removed = true;
manager->packetDropPruneConfigUpdated(pruneSpec);
manager->packetDropPruneConfigDeleted(itr);
}
}
dropPruneCfgSet = newPruneSet;
Expand Down Expand Up @@ -337,9 +335,7 @@ void FSPacketDropLogConfigSource::deleted(const fs::path& filePath) {
dropCfg.dropLogMode = DropLogModeEnumT::CONST_UNFILTERED_DROP_LOG;
manager->packetDropLogConfigUpdated(dropCfg);
for(auto itr: *dropPruneCfgSet) {
std::shared_ptr<PacketDropLogPruneSpec> pruneSpec(new PacketDropLogPruneSpec(itr));
pruneSpec->removed = true;
manager->packetDropPruneConfigUpdated(pruneSpec);
manager->packetDropPruneConfigDeleted(itr);
}
dropPruneCfgSet->clear();
LOG(INFO) << "Removed packet drop log config "
Expand Down
8 changes: 8 additions & 0 deletions agent-ovs/lib/include/opflexagent/ExtraConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ class ExtraConfigManager : private boost::noncopyable {
*/
void packetDropPruneConfigUpdated(std::shared_ptr<PacketDropLogPruneSpec> &pruneCfg);

/**
* Add or update a packet drop log prune config object
*
* @param filterName Drop log Prune spec filter name
*/
void packetDropPruneConfigDeleted(const std::string &filterName);

std::mutex prune_mutex;
drop_prune_map_t dropPruneMap;
/**
* The extraConfig listeners that have been registered
Expand Down
3 changes: 2 additions & 1 deletion agent-ovs/lib/test/ExtraConfigManager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ BOOST_FIXTURE_TEST_CASE( droplogpruneconfigsource, FSConfigFixture ) {
using modelgbp::observer::DropLogConfig;
using modelgbp::observer::DropLogModeEnumT;
using modelgbp::observer::DropPruneConfig;
fs::path path(temp / "a.droplogcfg");
fs::path path(temp / "b.droplogcfg");
fs::ofstream os(path);
os << "{"
<< "\"drop-log-enable\": true,\n"
Expand All @@ -126,6 +126,7 @@ BOOST_FIXTURE_TEST_CASE( droplogpruneconfigsource, FSConfigFixture ) {
BOOST_CHECK(dropLogCfg.get()->getDropLogMode().get()== DropLogModeEnumT::CONST_UNFILTERED_DROP_LOG);
BOOST_CHECK(dropLogCfg.get()->getDropLogEnable().get());
/*Test create prune filter*/
WAIT_FOR(DropPruneConfig::resolve(agent.getFramework(), dropPruneUri), 500);
boost::optional<shared_ptr<DropPruneConfig>> dropPruneCfg = DropPruneConfig::resolve(agent.getFramework(), dropPruneUri);
BOOST_CHECK(dropPruneCfg.get()->getFilterName().get() == "flt1");
BOOST_CHECK(dropPruneCfg.get()->getSrcAddress().get() == "1.2.3.4");
Expand Down
2 changes: 2 additions & 0 deletions agent-ovs/ovs/AccessFlowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,7 @@ void AccessFlowManager::rdConfigUpdated(const opflex::modb::URI& rdURI) {
}

void AccessFlowManager::packetDropLogConfigUpdated(const opflex::modb::URI& dropLogCfgURI) {
if (stopping) return;
using modelgbp::observer::DropLogConfig;
using modelgbp::observer::DropLogModeEnumT;
FlowEntryList dropLogFlows;
Expand Down Expand Up @@ -1004,6 +1005,7 @@ void AccessFlowManager::packetDropLogConfigUpdated(const opflex::modb::URI& drop
}

void AccessFlowManager::packetDropFlowConfigUpdated(const opflex::modb::URI& dropFlowCfgURI) {
if (stopping) return;
using modelgbp::observer::DropFlowConfig;
optional<shared_ptr<DropFlowConfig>> dropFlowCfg =
DropFlowConfig::resolve(agent.getFramework(), dropFlowCfgURI);
Expand Down
4 changes: 4 additions & 0 deletions agent-ovs/ovs/IntFlowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ void IntFlowManager::rdConfigUpdated(const opflex::modb::URI& rdURI) {
}

void IntFlowManager::packetDropLogConfigUpdated(const opflex::modb::URI& dropLogCfgURI) {
if(stopping)
return;
using modelgbp::observer::DropLogConfig;
using modelgbp::observer::DropLogModeEnumT;
FlowEntryList dropLogFlows;
Expand Down Expand Up @@ -458,6 +460,8 @@ void IntFlowManager::packetDropLogConfigUpdated(const opflex::modb::URI& dropLog
}

void IntFlowManager::packetDropFlowConfigUpdated(const opflex::modb::URI& dropFlowCfgURI) {
if(stopping)
return;
using modelgbp::observer::DropFlowConfig;
optional<shared_ptr<DropFlowConfig>> dropFlowCfg =
DropFlowConfig::resolve(agent.getFramework(), dropFlowCfgURI);
Expand Down

0 comments on commit d1e85e0

Please sign in to comment.