[DTrace-devel] [PATCH] Implement dt_bpf_map_lookup_fd()

Eugene Loh eugene.loh at oracle.com
Wed Aug 31 21:29:16 UTC 2022


Reviewed-by: Eugene Loh <eugene.loh at oracle.com>
but consider...

On 8/31/22 16:28, Kris Van Hees via DTrace-devel wrote:
> Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
> ---
>   libdtrace/dt_bpf.c | 20 +++++++++++++++++---
>   libdtrace/dt_bpf.h |  1 +
>   2 files changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
> index 81b6e6cb..504ddcb4 100644
> --- a/libdtrace/dt_bpf.c
> +++ b/libdtrace/dt_bpf.c
> @@ -244,18 +244,32 @@ dt_bpf_map_update(int fd, const void *key, const void *val)
>   }
>   
>   /*
> - * Retrieve the value in a map-of-maps, i.e. map[okey][ikey].
> + * Retrieve the fd for a map-in-map, i.e. map[okey] which is the fd of a map.
> + *
> + * Note: the caller is responsible for closing the fd.
>    */
>   int
> -dt_bpf_map_lookup_inner(int fd, const void *okey, const void *ikey, void *val)
> +dt_bpf_map_lookup_fd(int fd, const void *okey)
>   {
>   	uint32_t	id;
> -	int		rc;
>   
>   	if (dt_bpf_map_lookup(fd, okey, &id) < 0)
>   		return -1;
>   
>   	fd = dt_bpf_map_get_fd_by_id(id);
> +
> +	return fd;

Instead of reusing fd, how about just
         return dt_bpf_map_get_fd_by_id(id);

> +}
> +
> +/*
> + * Retrieve the value in a map-of-maps, i.e. map[okey][ikey].
> + */
> +int
> +dt_bpf_map_lookup_inner(int fd, const void *okey, const void *ikey, void *val)
> +{
> +	int		rc;
> +
> +	fd = dt_bpf_map_lookup_fd(fd, okey);
>   	if (fd < 0)
>   		return -1;
>   
> diff --git a/libdtrace/dt_bpf.h b/libdtrace/dt_bpf.h
> index 17761116..ab3862aa 100644
> --- a/libdtrace/dt_bpf.h
> +++ b/libdtrace/dt_bpf.h
> @@ -51,6 +51,7 @@ extern int dt_bpf_map_next_key(int fd, const void *key, void *nxt);
>   extern int dt_bpf_map_update(int fd, const void *key, const void *val);
>   extern int dt_bpf_map_delete(int fd, const void *key);
>   extern int dt_bpf_map_get_fd_by_id(uint32_t id);
> +extern int dt_bpf_map_lookup_fd(int fd, const void *okey);
>   extern int dt_bpf_map_lookup_inner(int fd, const void *okey, const void *ikey,
>   				   void *val);
>   extern int dt_bpf_map_update_inner(int fd, const void *okey, const void *ikey,



More information about the DTrace-devel mailing list