From d4a3baf4a10f3847a43811075e84f761af1ff5be Mon Sep 17 00:00:00 2001 From: Huapeng Zhou Date: Tue, 20 Dec 2016 13:10:12 -0800 Subject: [PATCH] do not close extern table when a module destructs --- src/cc/bpf_module.cc | 5 +++-- src/cc/frontends/clang/b_frontend_action.cc | 5 ++--- src/cc/table_desc.h | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cc/bpf_module.cc b/src/cc/bpf_module.cc index be0a524..ee39c00 100644 --- a/src/cc/bpf_module.cc +++ b/src/cc/bpf_module.cc @@ -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); + } } } } diff --git a/src/cc/frontends/clang/b_frontend_action.cc b/src/cc/frontends/clang/b_frontend_action.cc index 4e71873..397ecc6 100644 --- a/src/cc/frontends/clang/b_frontend_action.cc +++ b/src/cc/frontends/clang/b_frontend_action.cc @@ -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; diff --git a/src/cc/table_desc.h b/src/cc/table_desc.h index a5196e2..d299f5d 100644 --- a/src/cc/table_desc.h +++ b/src/cc/table_desc.h @@ -40,6 +40,7 @@ struct TableDesc { llvm::Function *key_snprintf; llvm::Function *leaf_snprintf; bool is_shared; + bool is_extern; }; } // namespace ebpf -- 2.7.4