Commit d4a3baf4 authored by Huapeng Zhou's avatar Huapeng Zhou

do not close extern table when a module destructs

parent 35d6ff8d
......@@ -118,10 +118,11 @@ BPFModule::~BPFModule() {
ctx_.reset();
if (tables_) {
for (auto table : *tables_) {
if (table.is_shared)
if (table.is_shared) {
SharedTables::instance()->remove_fd(table.name);
else
} else if (!table.is_extern) {
close(table.fd);
}
}
}
}
......
......@@ -631,7 +631,6 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) {
++i;
}
bool is_extern = false;
bpf_map_type map_type = BPF_MAP_TYPE_UNSPEC;
if (A->getName() == "maps/hash") {
map_type = BPF_MAP_TYPE_HASH;
......@@ -666,7 +665,7 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) {
} else if (A->getName() == "maps/stacktrace") {
map_type = BPF_MAP_TYPE_STACK_TRACE;
} else if (A->getName() == "maps/extern") {
is_extern = true;
table.is_extern = true;
table.fd = SharedTables::instance()->lookup_fd(table.name);
table.type = SharedTables::instance()->lookup_type(table.name);
} else if (A->getName() == "maps/export") {
......@@ -687,7 +686,7 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) {
return true;
}
if (!is_extern) {
if (!table.is_extern) {
if (map_type == BPF_MAP_TYPE_UNSPEC) {
error(Decl->getLocStart(), "unsupported map type: %0") << A->getName();
return false;
......
......@@ -40,6 +40,7 @@ struct TableDesc {
llvm::Function *key_snprintf;
llvm::Function *leaf_snprintf;
bool is_shared;
bool is_extern;
};
} // namespace ebpf
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment