mirror of
https://github.com/netdata/libbpf.git
synced 2026-11-06 18:00:15 +08:00
libbpf: Add bpf_prog_stream_open()
Expose the BPF_PROG_STREAM_OPEN command through a low-level libbpf wrapper. The options structure carries stream open flags, including non-blocking mode, while leaving room for future extensions. Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com> Link: https://patch.msgid.link/20260925045536.1480933-4-memxor@gmail.com
This commit is contained in:
1 parent
b198f8b67b
commit
f0b977cde9
3 files changed
+44
No files matched your search
@@ -1466,6 +1466,25 @@ int bpf_prog_stream_read(int prog_fd, __u32 stream_id, void *buf, __u32 buf_len,
|
||||
return libbpf_err_errno(err);
|
||||
}
|
||||
|
||||
int bpf_prog_stream_open(int prog_fd, __u32 stream_id,
|
||||
const struct bpf_prog_stream_open_opts *opts)
|
||||
{
|
||||
const size_t attr_sz = offsetofend(union bpf_attr, prog_stream_open);
|
||||
union bpf_attr attr;
|
||||
int fd;
|
||||
|
||||
if (!OPTS_VALID(opts, bpf_prog_stream_open_opts))
|
||||
return libbpf_err(-EINVAL);
|
||||
|
||||
memset(&attr, 0, attr_sz);
|
||||
attr.prog_stream_open.prog_fd = prog_fd;
|
||||
attr.prog_stream_open.stream_id = stream_id;
|
||||
attr.prog_stream_open.flags = OPTS_GET(opts, flags, 0);
|
||||
|
||||
fd = sys_bpf_fd(BPF_PROG_STREAM_OPEN, &attr, attr_sz);
|
||||
return libbpf_err_errno(fd);
|
||||
}
|
||||
|
||||
int bpf_prog_assoc_struct_ops(int prog_fd, int map_fd,
|
||||
struct bpf_prog_assoc_struct_ops_opts *opts)
|
||||
{
|
||||
|
||||
@@ -759,10 +759,34 @@ struct bpf_prog_stream_read_opts {
|
||||
*
|
||||
* @return The number of bytes read, on success; negative error code, otherwise
|
||||
* (errno is also set to the error code)
|
||||
*
|
||||
* For blocking reads and polling, prefer **bpf_prog_stream_open**.
|
||||
*/
|
||||
LIBBPF_API int bpf_prog_stream_read(int prog_fd, __u32 stream_id, void *buf, __u32 buf_len,
|
||||
struct bpf_prog_stream_read_opts *opts);
|
||||
|
||||
struct bpf_prog_stream_open_opts {
|
||||
size_t sz;
|
||||
__u32 flags;
|
||||
size_t :0;
|
||||
};
|
||||
#define bpf_prog_stream_open_opts__last_field flags
|
||||
|
||||
/**
|
||||
* @brief **bpf_prog_stream_open** opens a file descriptor for a BPF stream of
|
||||
* a given BPF program.
|
||||
*
|
||||
* @param prog_fd FD for the BPF program whose BPF stream is to be opened.
|
||||
* @param stream_id ID of the BPF stream to be opened.
|
||||
* @param opts optional options, can be NULL. BPF_F_STREAM_NONBLOCK requests a
|
||||
* non-blocking descriptor.
|
||||
*
|
||||
* @return A new stream FD, on success; negative error code, otherwise (errno
|
||||
* is also set to the error code)
|
||||
*/
|
||||
LIBBPF_API int bpf_prog_stream_open(int prog_fd, __u32 stream_id,
|
||||
const struct bpf_prog_stream_open_opts *opts);
|
||||
|
||||
struct bpf_prog_assoc_struct_ops_opts {
|
||||
size_t sz;
|
||||
__u32 flags;
|
||||
|
||||
@@ -459,6 +459,7 @@ LIBBPF_1.7.0 {
|
||||
LIBBPF_1.8.0 {
|
||||
global:
|
||||
bpf_map__attach_cgroup_opts;
|
||||
bpf_prog_stream_open;
|
||||
bpf_program__add_flags;
|
||||
bpf_program__attach_tracing_multi;
|
||||
bpf_program__clear_flags;
|
||||
|
||||
Reference in new issue
Block a user