Lines Matching defs:fd

303 # define zclose(fd) ({			\
305 if ((fd) >= 0) \
306 ___err = close((fd)); \
307 fd = -1; \
451 int fd;
530 int fd;
596 /* BTF fd index to be patched in for insn->off, this is
609 int fd;
629 int fd;
731 zclose(prog->fd);
794 prog->fd = -1;
1114 map->mod_btf_fd = mod_btf ? mod_btf->fd : -1;
1230 prog->attach_btf_obj_fd = mod_btf->fd;
1460 obj->efile.fd = -1;
1490 zclose(obj->efile.fd);
1510 obj->efile.fd = open(obj->path, O_RDONLY | O_CLOEXEC);
1511 if (obj->efile.fd < 0) {
1520 elf = elf_begin(obj->efile.fd, ELF_C_READ_MMAP, NULL);
1692 int fd;
1694 fd = ensure_good_fd(sys_memfd_create("libbpf-placeholder-fd", MFD_CLOEXEC));
1695 if (fd < 0)
1697 return fd;
1724 map->fd = create_placeholder_fd();
1725 if (map->fd < 0)
1726 return ERR_PTR(map->fd);
2886 map->inner_map->fd = create_placeholder_fd();
2887 if (map->inner_map->fd < 0)
2888 return map->inner_map->fd;
3540 /* Pretend to have valid FD to pass various fd >= 0 checks.
3541 * This fd == 0 will not be used with any syscall and will be reset to -1 eventually.
3551 /* move fd to libbpf's BTF */
4749 static int bpf_get_map_info_from_fdinfo(int fd, struct bpf_map_info *info)
4756 snprintf(file, sizeof(file), "/proc/%d/fdinfo/%d", getpid(), fd);
4799 int bpf_map__reuse_fd(struct bpf_map *map, int fd)
4807 err = bpf_map_get_info_by_fd(fd, &info, &len);
4809 err = bpf_get_map_info_from_fdinfo(fd, &info);
4827 new_fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
4833 err = reuse_fd(map->fd, new_fd);
5068 err = bpf_map_update_elem(map->fd, &zero, map->mmaped, 0);
5079 err = bpf_map_freeze(map->fd);
5140 map->inner_map_fd = map->inner_map->fd;
5178 /* We keep pretenting we have valid FD to pass various fd >= 0
5181 * This placeholder fd will not be used with any syscall and
5184 map_fd = map->fd;
5209 map->inner_map->fd = -1;
5218 if (map->fd == map_fd)
5224 * map->fd stays valid but now point to what map_fd points to.
5226 return reuse_fd(map->fd, map_fd);
5233 int fd, err = 0;
5240 fd = targ_map->fd;
5247 err = bpf_map_update_elem(map->fd, &i, &fd, 0);
5251 pr_warn("map '%s': failed to initialize slot [%d] to map '%s' fd=%d: %d\n",
5252 map->name, i, targ_map->name, fd, err);
5255 pr_debug("map '%s': slot [%d] set to map '%s' fd=%d\n",
5256 map->name, i, targ_map->name, fd);
5269 int fd, err;
5279 fd = bpf_program__fd(targ_prog);
5281 err = bpf_map_update_elem(map->fd, &i, &fd, 0);
5284 pr_warn("map '%s': failed to initialize slot [%d] to prog '%s' fd=%d: %d\n",
5285 map->name, i, targ_prog->name, fd, err);
5288 pr_debug("map '%s': slot [%d] set to prog '%s' fd=%d\n",
5289 map->name, i, targ_prog->name, fd);
5381 if (retried && map->fd < 0) {
5390 pr_debug("map '%s': skipping creation (preset fd=%d)\n",
5391 map->name, map->fd);
5397 pr_debug("map '%s': created successfully, fd=%d\n",
5398 map->name, map->fd);
5409 map->fd, 0);
5450 zclose(obj->maps[j].fd);
5546 int err, fd;
5575 fd = bpf_btf_get_fd_by_id(id);
5576 if (fd < 0) {
5589 err = bpf_btf_get_info_by_fd(fd, &info, &len);
5598 close(fd);
5602 btf = btf_get_from_fd(fd, obj->btf_vmlinux);
5619 mod_btf->fd = fd;
5628 close(fd);
6011 insn[0].imm = map->fd;
6025 insn[0].imm = map->fd;
6039 insn[0].imm = obj->maps[obj->kconfig_map_idx].fd;
7498 if (bpf_prog_bind_map(ret, map->fd, NULL)) {
7823 obj->license, obj->kern_version, &prog->fd);
8010 zclose(obj->maps[i].fd);
8189 ext->ksym.kernel_btf_obj_fd = mod_btf ? mod_btf->fd : 0;
8233 /* set index for module BTF fd in fd_array, if unset */
8237 pr_warn("extern (func ksym) '%s': module BTF fd index %d too big to fit in bpf_insn offset\n",
8241 /* Cannot use index 0 for module BTF fd */
8251 obj->fd_array[obj->fd_array_cnt++] = mod_btf->fd;
8262 ext->ksym.kernel_btf_obj_fd = mod_btf ? mod_btf->fd : 0;
8489 close(obj->btf_modules[i].fd);
8578 if (prog->fd < 0) {
8591 if (bpf_obj_pin(prog->fd, path)) {
8606 if (prog->fd < 0) {
8633 if (map->fd < 0) {
8673 if (bpf_obj_pin(map->fd, map->pin_path)) {
8958 if (map->fd >= 0)
8959 zclose(map->fd);
9181 if (prog->fd < 0)
9184 return prog->fd;
9931 *btf_obj_fd = mod->fd;
10022 return map->fd;
10294 int bpf_map__set_inner_map_fd(struct bpf_map *map, int fd)
10308 map->inner_map_fd = fd;
10402 if (map->fd < 0) {
10446 return bpf_map_lookup_elem_flags(map->fd, key, value, flags);
10459 return bpf_map_update_elem(map->fd, key, value, flags);
10471 return bpf_map_delete_elem_flags(map->fd, key, flags);
10484 return bpf_map_lookup_and_delete_elem_flags(map->fd, key, value, flags);
10496 return bpf_map_get_next_key(map->fd, cur_key, next_key);
10567 return link->fd;
10577 return libbpf_err_errno(close(link->fd));
10583 int fd;
10585 fd = bpf_obj_get(path);
10586 if (fd < 0) {
10587 fd = -errno;
10588 pr_warn("failed to open link at %s: %d\n", path, fd);
10589 return libbpf_err_ptr(fd);
10594 close(fd);
10598 link->fd = fd;
10611 return bpf_link_detach(link->fd) ? -errno : 0;
10631 if (bpf_obj_pin(link->fd, link->pin_path)) {
10637 pr_debug("link fd=%d: pinned at %s\n", link->fd, link->pin_path);
10652 pr_debug("link fd=%d: unpinned from %s\n", link->fd, link->pin_path);
10677 if (perf_link->perf_event_fd != link->fd)
10679 close(link->fd);
10681 /* legacy uprobe/kprobe needs to be removed after perf event fd closure */
10746 link->link.fd = link_fd;
10763 link->link.fd = pfd;
10895 int fd, n, err = 0;
10906 fd = open(file, O_WRONLY | O_APPEND | O_CLOEXEC, 0);
10907 if (fd < 0)
10910 if (write(fd, buf, n) < 0)
10913 close(fd);
11506 link->fd = link_fd;
11996 link->fd = link_fd;
12457 link->fd = pfd;
12541 link->fd = pfd;
12604 link->fd = link_fd;
12774 link->fd = link_fd;
12821 link->fd = link_fd;
12869 return bpf_map_delete_elem(link->fd, &zero);
12871 return close(link->fd);
12878 int err, fd;
12883 if (map->fd < 0) {
12893 err = bpf_map_update_elem(map->fd, &zero, map->st_ops->kern_vdata, 0);
12908 link->link.fd = map->fd;
12913 fd = bpf_link_create(map->fd, 0, BPF_STRUCT_OPS, NULL);
12914 if (fd < 0) {
12916 return libbpf_err_ptr(fd);
12919 link->link.fd = fd;
12920 link->map_fd = map->fd;
12937 if (map->fd < 0) {
12947 err = bpf_map_update_elem(map->fd, &zero, map->st_ops->kern_vdata, 0);
12956 err = bpf_link_update(link->fd, map->fd, NULL);
12960 st_ops_link->map_fd = map->fd;
13036 int fd;
13064 if (cpu_buf->fd >= 0) {
13065 ioctl(cpu_buf->fd, PERF_EVENT_IOC_DISABLE, 0);
13066 close(cpu_buf->fd);
13112 cpu_buf->fd = syscall(__NR_perf_event_open, attr, -1 /* pid */, cpu,
13114 if (cpu_buf->fd < 0) {
13123 cpu_buf->fd, 0);
13132 if (ioctl(cpu_buf->fd, PERF_EVENT_IOC_ENABLE, 0) < 0) {
13321 &cpu_buf->fd, 0);
13325 cpu, map_key, cpu_buf->fd,
13332 if (epoll_ctl(pb->epoll_fd, EPOLL_CTL_ADD, cpu_buf->fd,
13336 cpu, cpu_buf->fd,
13463 return cpu_buf->fd;
13621 int fd, err = 0, len;
13624 fd = open(fcpu, O_RDONLY | O_CLOEXEC);
13625 if (fd < 0) {
13630 len = read(fd, buf, sizeof(buf));
13631 close(fd);
13843 int prot, map_fd = map->fd;