public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Daniel Xu <dxu@dxuuu.xyz>
Cc: ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net,
	martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
	john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com,
	haoluo@google.com, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next] libbpf: Add bpf_object__unpin()
Date: Wed, 23 Aug 2023 13:48:09 +0200	[thread overview]
Message-ID: <ZOXx+emQcLTKcPwP@krava> (raw)
In-Reply-To: <aeb83832ae61bbf463e1b2e39c1e30c3b227f5a5.1692769396.git.dxu@dxuuu.xyz>

On Tue, Aug 22, 2023 at 11:44:25PM -0600, Daniel Xu wrote:
> For bpf_object__pin_programs() there is bpf_object__unpin_programs().
> Likewise bpf_object__unpin_maps() for bpf_object__pin_maps().
> 
> But no bpf_object__unpin() for bpf_object__pin(). Adding the former adds
> symmetry to the API.
> 
> It's also convenient for cleanup in application code. It's an API I
> would've used if it was available for a repro I was writing earlier.
> 
> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
> ---
>  tools/lib/bpf/libbpf.c   | 15 +++++++++++++++
>  tools/lib/bpf/libbpf.h   |  1 +
>  tools/lib/bpf/libbpf.map |  1 +
>  3 files changed, 17 insertions(+)
> 
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 4c3967d94b6d..96ff1aa4bf6a 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -8376,6 +8376,21 @@ int bpf_object__pin(struct bpf_object *obj, const char *path)
>  	return 0;
>  }
>  
> +int bpf_object__unpin(struct bpf_object *obj, const char *path)
> +{
> +	int err;
> +
> +	err = bpf_object__unpin_programs(obj, path);
> +	if (err)
> +		return libbpf_err(err);
> +
> +	err = bpf_object__unpin_maps(obj, path);
> +	if (err)
> +		return libbpf_err(err);
> +
> +	return 0;
> +}
> +
>  static void bpf_map__destroy(struct bpf_map *map)
>  {
>  	if (map->inner_map) {
> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> index 2e3eb3614c40..0e52621cba43 100644
> --- a/tools/lib/bpf/libbpf.h
> +++ b/tools/lib/bpf/libbpf.h
> @@ -266,6 +266,7 @@ LIBBPF_API int bpf_object__pin_programs(struct bpf_object *obj,
>  LIBBPF_API int bpf_object__unpin_programs(struct bpf_object *obj,
>  					  const char *path);
>  LIBBPF_API int bpf_object__pin(struct bpf_object *object, const char *path);
> +LIBBPF_API int bpf_object__unpin(struct bpf_object *object, const char *path);
>  
>  LIBBPF_API const char *bpf_object__name(const struct bpf_object *obj);
>  LIBBPF_API unsigned int bpf_object__kversion(const struct bpf_object *obj);
> diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
> index 841a2f9c6fef..abf8fea3988e 100644
> --- a/tools/lib/bpf/libbpf.map
> +++ b/tools/lib/bpf/libbpf.map
> @@ -399,4 +399,5 @@ LIBBPF_1.3.0 {
>  		bpf_program__attach_netfilter;
>  		bpf_program__attach_tcx;
>  		bpf_program__attach_uprobe_multi;
> +		bpf_object__unpin;

nit, I think we add in here in alphabetical order

jirka

>  } LIBBPF_1.2.0;
> -- 
> 2.41.0
> 

  parent reply	other threads:[~2023-08-23 11:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-23  5:44 [PATCH bpf-next] libbpf: Add bpf_object__unpin() Daniel Xu
2023-08-23 11:30 ` Song Liu
2023-08-23 11:48 ` Jiri Olsa [this message]
2023-08-23 17:19 ` Andrii Nakryiko
2023-08-23 18:08   ` Song Liu
2023-08-23 18:43   ` Daniel Xu
2023-08-23 21:16     ` Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZOXx+emQcLTKcPwP@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dxu@dxuuu.xyz \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox