Lines Matching +full:no +full:- +full:can +full:- +full:fd

1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
51 t = btf__type_by_id(kern_btf, info->btf_vmlinux_value_type_id); in get_kern_struct_ops_name()
52 st_ops_name = btf__name_by_offset(kern_btf, t->name_off); in get_kern_struct_ops_name()
72 p_err("can't find bpf_map_info from btf_vmlinux"); in get_map_info_type_id()
78 map_info_alloc_len = map_info_type->size; in get_map_info_type_id()
117 * It returns the fd in "*res_fd" and map_info in "*info".
118 * In the very first iteration, info->id should be 0.
119 * An optional map "*name" filter can be specified.
120 * The filter can be made more flexible in the future.
121 * e.g. filter by kernel-struct-ops-name, regex-name, glob-name, ...etc.
125 * The caller can continue to call get_next in the future.
126 * 0: No struct_ops map is returned.
128 * -1: Error and the caller should abort the iteration.
133 __u32 id = info->id; in get_next_struct_ops_map()
134 int err, fd; in get_next_struct_ops_map() local
141 p_err("can't get next map: %s", strerror(errno)); in get_next_struct_ops_map()
142 return -1; in get_next_struct_ops_map()
145 fd = bpf_map_get_fd_by_id(id); in get_next_struct_ops_map()
146 if (fd < 0) { in get_next_struct_ops_map()
149 p_err("can't get map by id (%u): %s", in get_next_struct_ops_map()
151 return -1; in get_next_struct_ops_map()
154 err = bpf_map_get_info_by_fd(fd, info, &info_len); in get_next_struct_ops_map()
156 p_err("can't get map info: %s", strerror(errno)); in get_next_struct_ops_map()
157 close(fd); in get_next_struct_ops_map()
158 return -1; in get_next_struct_ops_map()
161 if (info->type == BPF_MAP_TYPE_STRUCT_OPS && in get_next_struct_ops_map()
162 (!name || !strcmp(name, info->name))) { in get_next_struct_ops_map()
163 *res_fd = fd; in get_next_struct_ops_map()
166 close(fd); in get_next_struct_ops_map()
172 if (res->nr_errs || (!res->nr_maps && must_have_one_map)) in cmd_retval()
173 return -1; in cmd_retval()
179 typedef int (*work_func)(int fd, const struct bpf_map_info *info, void *data,
184 * Then call "func(fd, info, data, wtr)" on each struct_ops map found.
192 int fd, err; in do_search() local
202 while ((err = get_next_struct_ops_map(name, &fd, info, info_len)) == 1) { in do_search()
204 err = func(fd, info, data, wtr); in do_search()
207 close(fd); in do_search()
220 p_err("no struct_ops found for %s", name); in do_search()
225 * However, "-j" is enabled and there is no errs here, in do_search()
243 int fd; in do_one_id() local
252 fd = bpf_map_get_fd_by_id(id); in do_one_id()
253 if (fd < 0) { in do_one_id()
254 p_err("can't get map by id (%lu): %s", id, strerror(errno)); in do_one_id()
265 if (bpf_map_get_info_by_fd(fd, info, &info_len)) { in do_one_id()
266 p_err("can't get map info: %s", strerror(errno)); in do_one_id()
271 if (info->type != BPF_MAP_TYPE_STRUCT_OPS) { in do_one_id()
272 p_err("%s id %u is not a struct_ops map", info->name, info->id); in do_one_id()
282 if (func(fd, info, data, wtr)) in do_one_id()
288 * However, "-j" is enabled and there is no errs here, in do_one_id()
299 close(fd); in do_one_id()
319 static int __do_show(int fd, const struct bpf_map_info *info, void *data, in __do_show() argument
324 jsonw_uint_field(wtr, "id", info->id); in __do_show()
325 jsonw_string_field(wtr, "name", info->name); in __do_show()
330 printf("%u: %-15s %-32s\n", info->id, info->name, in __do_show()
356 static int __do_dump(int fd, const struct bpf_map_info *info, void *data, in __do_dump() argument
361 const struct btf *kern_btf = d->btf; in __do_dump()
366 /* note: d->jw == wtr */ in __do_dump()
368 kern_btf = d->btf; in __do_dump()
374 info->btf_vmlinux_value_type_id); in __do_dump()
376 struct_ops_type->name_off); in __do_dump()
377 value = calloc(1, info->value_size); in __do_dump()
380 return -1; in __do_dump()
383 if (bpf_map_lookup_elem(fd, &zero, value)) { in __do_dump()
384 p_err("can't lookup struct_ops map %s id %u", in __do_dump()
385 info->name, info->id); in __do_dump()
387 return -1; in __do_dump()
397 btf_dumper_type(d, info->btf_vmlinux_value_type_id, value); in __do_dump()
423 return -1; in do_dump()
428 p_err("can't create json writer"); in do_dump()
429 return -1; in do_dump()
448 static int __do_unregister(int fd, const struct bpf_map_info *info, void *data, in __do_unregister() argument
453 if (bpf_map_delete_elem(fd, &zero)) { in __do_unregister()
454 p_err("can't unload %s %s id %u: %s", in __do_unregister()
455 get_kern_struct_ops_name(info), info->name, in __do_unregister()
456 info->id, strerror(errno)); in __do_unregister()
457 return -1; in __do_unregister()
461 get_kern_struct_ops_name(info), info->name, in __do_unregister()
462 info->id); in __do_unregister()
492 return -1; in pin_link()
519 p_err("can't mount bpffs for pinning"); in do_register()
520 return -1; in do_register()
529 return -1; in do_register()
535 return -1; in do_register()
544 p_err("can't register struct_ops %s: %s", in do_register()
556 p_info("Registered %s but can't find id: %s", in do_register()
570 p_err("Registered %s but can't find link id: %s", in do_register()
576 p_err("can't pin link %u for %s: %s", in do_register()
594 return -1; in do_register()
597 p_err("no struct_ops found in %s", file); in do_register()
598 return -1; in do_register()
624 bin_name, argv[-2]); in do_help()