簡體   English   中英

如果我有 bpf_map object,如何使用 bpf_object__find_map_by_name(bpf_object,"hash_map") 獲取 map fd 和 max extries; ebpf

[英]how to get map fd and max extries if I have bpf_map object by using bpf_object__find_map_by_name(bpf_object,"hash_map"); ebpf

所以fdmax_entriesstruct bpf_map成員定義(我需要)在源文件(libbpf.c)中,而 libbpf.h 只包含 ebpf map 的聲明,如struct bpf_map map; 所以我不能取消引用一個指針(我有struct bpf_map的)來獲取存儲在 struct 內的 struct 中的 fd 和 max extries。

首先,有什么方法可以驗證從這兩個 function 返回的內容是否有效。 包含 libbpf.h 足以包含libbpf_get_error function

 struct bpf_object *obj=bpf_object__open(filename);
 if (libbpf_get_error(obj)) {
    printf("ERROR: opening BPF object file failed\n");
   }

 struct bpf_map *map=bpf_object__find_map_by_name(obj,"hash_map");    
 if (libbpf_get_error(map)) {
    printf("ERROR: finding map\n");
 }

並從這里繼續前進。 如果我有struct bpf_map object,我究竟如何獲得struct bpf_mapstruct bpf_map_def bpf_map_def 的成員

誰能告訴我這個?

我對 fd 和 max_entries 感興趣; 如果 ebpf libbpf 不支持它,那么 function 中是否有任何系統調用號值

   long syscall(long number, ...);

和給我這個信息的參數列表。

謝謝

無需自己取消引用指針,結構是故意不透明的。 只需使用libbpf中的相關函數:

LIBBPF_API int bpf_map__fd(const struct bpf_map *map);
LIBBPF_API __u32 bpf_map__max_entries(const struct bpf_map *map);

如果 ebpf libbpf 不支持它,那么 function syscall(...)中是否有任何系統調用號值

有,但這只能在創建 map之后從 kernel 中檢索信息(這無疑是您想要的,因為無論如何您都在尋找 fd)。 The BPF_MAP_GET_FD_BY_ID subcommand for the bpf() syscall ( syscall(__NR_bpf, cmd, attr, size) , see man bpf ), would give you the relevant file descriptor, provided you know the map id, and the BPF_OBJ_GET_INFO_BY_FD subcommand , with the relevant arguments將允許您找到最大條目數。 但是你最終會重新實現 libbpf

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM