[DTrace-devel] [PATCH 4/5] Implement dt_bpf_map_lookup_inner() and dt_bpf_map_update_inner()
Kris Van Hees
kris.van.hees at oracle.com
Tue Aug 23 00:08:57 UTC 2022
On Mon, Aug 22, 2022 at 03:18:30PM -0400, Eugene Loh wrote:
> Reviewed-by: Eugene Loh <eugene.loh at oracle.com>
>
> For the dt_bpf_map_get_fd_by_id() comment, I assume:
> s/based on it id/based on its id/
Thanks.
> Personally, instead of key1/key2, it'd be better to stick to the in/out
> terminology that is otherwise used. In fact, converting "name[key1][key2]" to
> the in/out terminology would be a nice way of illustrating what in/out mean.
Good point.
> Will dt_bpf_map_get_fd_by_id() be used outside this file? That is, should it
> be "static" rather than declared in dt_bpf.h?
It is an API function and as such would properly not be declared static, so
that it can be used from coce outside this file.
> âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
> From: Kris Van Hees via DTrace-devel <dtrace-devel at oss.oracle.com>
> Sent: Friday, August 19, 2022 10:26 AM
> To: dtrace-devel at oss.oracle.com <dtrace-devel at oss.oracle.com>
> Subject: [DTrace-devel] [PATCH 4/5] Implement dt_bpf_map_lookup_inner() and
> dt_bpf_map_update_inner()
>
> Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
> ---
> libdtrace/dt_bpf.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++
> libdtrace/dt_bpf.h | 5 ++++
> 2 files changed, 64 insertions(+)
>
> diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
> index 7a886278..66c76022 100644
> --- a/libdtrace/dt_bpf.c
> +++ b/libdtrace/dt_bpf.c
> @@ -164,6 +164,20 @@ dt_bpf_map_create_meta(enum bpf_map_type otype, const char
> *name,
> return ofd;
> }
>
> +/*
> + * Get a file descriptor for a BPF map based on it id.
> + */
> +int
> +dt_bpf_map_get_fd_by_id(uint32_t id)
> +{
> + union bpf_attr attr;
> +
> + memset(&attr, 0, sizeof(attr));
> + attr.map_id = id;
> +
> + return bpf(BPF_MAP_GET_FD_BY_ID, &attr);
> +}
> +
> /*
> * Load the value for the given key in the map referenced by the given fd.
> */
> @@ -228,6 +242,51 @@ dt_bpf_map_update(int fd, const void *key, const void
> *val)
> return bpf(BPF_MAP_UPDATE_ELEM, &attr);
> }
>
> +/*
> + * Retrieve the value in a map-of-maps, i.e. map[key1][key2] = value.
> + */
> +int
> +dt_bpf_map_lookup_inner(int fd, const void *key1, const void *key2, void *val)
> +{
> + uint32_t id;
> + int rc;
> +
> + if (dt_bpf_map_lookup(fd, key1, &id) < 0)
> + return -1;
> +
> + fd = dt_bpf_map_get_fd_by_id(id);
> + if (fd < 0)
> + return -1;
> +
> + rc = dt_bpf_map_lookup(fd, key2, val);
> + close(fd);
> +
> + return rc;
> +}
> +
> +/*
> + * Store the value in a map-of-maps, i.e. map[key1][key2] = value.
> + */
> +int
> +dt_bpf_map_update_inner(int fd, const void *key1, const void *key2,
> + const void *val)
> +{
> + uint32_t id;
> + int rc;
> +
> + if (dt_bpf_map_lookup(fd, key1, &id) < 0)
> + return -1;
> +
> + fd = dt_bpf_map_get_fd_by_id(id);
> + if (fd < 0)
> + return -1;
> +
> + rc = dt_bpf_map_update(fd, key2, val);
> + close(fd);
> +
> + return rc;
> +}
> +
> static int
> have_helper(uint32_t func_id)
> {
> diff --git a/libdtrace/dt_bpf.h b/libdtrace/dt_bpf.h
> index f8c75012..7a16c03d 100644
> --- a/libdtrace/dt_bpf.h
> +++ b/libdtrace/dt_bpf.h
> @@ -50,6 +50,11 @@ extern int dt_bpf_map_lookup(int fd, const void *key, void
> *val);
> 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_inner(int fd, const void *key1, const void *key2,
> + void *val);
> +extern int dt_bpf_map_update_inner(int fd, const void *key1, const void *key2,
> + const void *val);
> extern int dt_bpf_load_progs(struct dtrace_hdl *, uint_t);
> extern void dt_bpf_init_helpers(struct dtrace_hdl *dtp);
>
> --
> 2.34.1
>
>
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel
More information about the DTrace-devel
mailing list