Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion so/bpf-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int BPFManager::bpf_find_map(const char *name)
int fd = -1;
struct bpf_map_info info = {};
u32 len = sizeof(info);
std::string map_pin_path(PIN_PATH "/map-");
std::string map_pin_path(PIN_PATH "/");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么改这

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为在bpf-manager.cpp:207中bpf_object__pin_maps(m_obj->obj, PIN_PATH);这个函数会调用 libbpf,把当前 BPF object 里的所有 maps pin 到 PIN_PATH 下。但是libbpf 默认会用 map 自己的名字作为最后一级文件名,而没有map-这个前缀。以map-dk_shared_mem 这个map为例, 会导致

  1. 存在性判断永远看错地方,代码以为 /sys/fs/bpf/dkapture/map-dk_shared_mem 不存在,于是误判“需要新建”。
  2. 实际创建时又去创建真正的 dk_shared_mem, 但这个真实 pin 已经存在,于是 libbpf 报: failed to pin map: File exists
  3. 并且当前仓库里没有把 map pin 成 map-xxx 的定义

map_pin_path += name;
if (access(map_pin_path.c_str(), F_OK) != 0)
{
Expand Down
Loading