提交 357b3cc3 编写于 作者: C Chris J Arges 提交者: Daniel Borkmann

bpftool: Ensure bytes_memlock json output is correct

If a BPF map is created over 2^32 the memlock value as displayed in JSON
format will be incorrect. Use atoll instead of atoi so that the correct
number is displayed.

  ```
  $ bpftool map create /sys/fs/bpf/test_bpfmap type hash key 4 \
    value 1024 entries 4194304 name test_bpfmap
  $ bpftool map list
  1: hash  name test_bpfmap  flags 0x0
          key 4B  value 1024B  max_entries 4194304  memlock 4328521728B
  $ sudo bpftool map list -j | jq .[].bytes_memlock
  33554432
  ```
Signed-off-by: NChris J Arges <carges@cloudflare.com>
Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/b6601087-0b11-33cc-904a-1133d1500a10@cloudflare.com
上级 1b773d00
...@@ -504,7 +504,7 @@ static int show_map_close_json(int fd, struct bpf_map_info *info) ...@@ -504,7 +504,7 @@ static int show_map_close_json(int fd, struct bpf_map_info *info)
jsonw_uint_field(json_wtr, "max_entries", info->max_entries); jsonw_uint_field(json_wtr, "max_entries", info->max_entries);
if (memlock) if (memlock)
jsonw_int_field(json_wtr, "bytes_memlock", atoi(memlock)); jsonw_int_field(json_wtr, "bytes_memlock", atoll(memlock));
free(memlock); free(memlock);
if (info->type == BPF_MAP_TYPE_PROG_ARRAY) { if (info->type == BPF_MAP_TYPE_PROG_ARRAY) {
......
...@@ -485,7 +485,7 @@ static void print_prog_json(struct bpf_prog_info *info, int fd) ...@@ -485,7 +485,7 @@ static void print_prog_json(struct bpf_prog_info *info, int fd)
memlock = get_fdinfo(fd, "memlock"); memlock = get_fdinfo(fd, "memlock");
if (memlock) if (memlock)
jsonw_int_field(json_wtr, "bytes_memlock", atoi(memlock)); jsonw_int_field(json_wtr, "bytes_memlock", atoll(memlock));
free(memlock); free(memlock);
if (info->nr_map_ids) if (info->nr_map_ids)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册