Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1566254

Re: [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin()

From "Wangnan (F)" <wangnan0@huawei.com>
Newsgroups linux.kernel
Subject Re: [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin()
Date 2017-01-25 02:10 +0100
Message-ID <t3kg1-3qv-3@gated-at.bofh.it> (permalink)
References <t2BsB-8iC-3@gated-at.bofh.it> <t2BsC-8iC-25@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw



On 2017/1/23 9:11, Joe Stringer wrote:
> Add a new API to pin a BPF program to the filesystem. The user can
> specify the path full path within a BPF filesystem to pin the program.
> Programs with multiple instances are pinned as 'foo', 'foo_1', 'foo_2',
> and so on.
>
> Signed-off-by: Joe Stringer <joe@ovn.org>
> ---
> v2: Don't automount BPF filesystem
>      Split program, map, object pinning into separate APIs and separate
>      patches.
> ---
>   tools/lib/bpf/libbpf.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++
>   tools/lib/bpf/libbpf.h |  1 +
>   2 files changed, 77 insertions(+)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index e6cd62b1264b..eea5c74808f7 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -4,6 +4,7 @@
>    * Copyright (C) 2013-2015 Alexei Starovoitov <ast@kernel.org>
>    * Copyright (C) 2015 Wang Nan <wangnan0@huawei.com>
>    * Copyright (C) 2015 Huawei Inc.
> + * Copyright (C) 2017 Nicira, Inc.
>    *
>    * This program is free software; you can redistribute it and/or
>    * modify it under the terms of the GNU Lesser General Public
> @@ -22,6 +23,7 @@
>   #include <stdlib.h>
>   #include <stdio.h>
>   #include <stdarg.h>
> +#include <libgen.h>
>   #include <inttypes.h>
>   #include <string.h>
>   #include <unistd.h>
> @@ -31,7 +33,10 @@
>   #include <linux/err.h>
>   #include <linux/kernel.h>
>   #include <linux/bpf.h>
> +#include <linux/magic.h>
>   #include <linux/list.h>
> +#include <linux/limits.h>
> +#include <sys/vfs.h>
>   #include <libelf.h>
>   #include <gelf.h>
>   
> @@ -1237,6 +1242,77 @@ int bpf_object__load(struct bpf_object *obj)
>   	return err;
>   }
>   
> +static int check_path(const char *path)
> +{
> +	struct statfs st_fs;
> +	char *dname, *dir;
> +	int err = 0;
> +
> +	if (path == NULL)
> +		return -EINVAL;
> +
> +	dname = strdup(path);
> +	dir = dirname(dname);
> +	if (statfs(dir, &st_fs)) {
> +		pr_warning("failed to statfs %s: %s\n", dir, strerror(errno));
> +		err = -errno;
> +	}
> +	free(dname);
> +
> +	if (!err && st_fs.f_type != BPF_FS_MAGIC) {
> +		pr_warning("specified path %s is not on BPF FS\n", path);
> +		err = -EINVAL;
> +	}
> +
> +	return err;
> +}
> +
> +int bpf_program__pin(struct bpf_program *prog, const char *path)

In your next patch please let caller select one instance:

int bpf_program__pin(struct bpf_program *prog, int instance, const char 
*path)
(please choose a better name)

Then your can wrap it with another function to pin all instances, implement
naming schema (%s_%d) there.

Then implement naming schema in bpf_object__pin like:

%s/objectname_mapname
%s/objectname_progname_%d

and make a bpf_{map,program}__pin the raw pinning functions with no 
naming schema.

Thank you.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCHv2 perf/core 0/7] Libbpf improvements Joe Stringer <joe@ovn.org> - 2017-01-23 02:20 +0100
  [PATCHv2 perf/core 6/7] tools lib bpf: Add bpf_map__pin() Joe Stringer <joe@ovn.org> - 2017-01-23 02:20 +0100
  [PATCHv2 perf/core 4/7] tools lib bpf: Add libbpf_get_error() Joe Stringer <joe@ovn.org> - 2017-01-23 02:20 +0100
    [tip:perf/core] tools lib bpf: Add libbpf_get_error() tip-bot for Joe Stringer <tipbot@zytor.com> - 2017-01-26 16:40 +0100
  [PATCHv2 perf/core 7/7] tools lib bpf: Add bpf_object__pin() Joe Stringer <joe@ovn.org> - 2017-01-23 02:20 +0100
  [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin() Joe Stringer <joe@ovn.org> - 2017-01-23 02:20 +0100
    Re: [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin() "Wangnan (F)" <wangnan0@huawei.com> - 2017-01-25 02:10 +0100
      Re: [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin() Joe Stringer <joe@ovn.org> - 2017-01-25 02:20 +0100
        Re: [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin() "Wangnan (F)" <wangnan0@huawei.com> - 2017-01-25 03:20 +0100
          Re: [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin() Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-26 20:40 +0100
            Re: [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin() Joe Stringer <joe@ovn.org> - 2017-01-26 20:50 +0100
    Re: [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin() "Wangnan (F)" <wangnan0@huawei.com> - 2017-01-25 02:10 +0100
  [PATCHv2 perf/core 1/7] tools lib bpf: Fix map offsets in relocation Joe Stringer <joe@ovn.org> - 2017-01-23 02:20 +0100
    [tip:perf/core] tools lib bpf: Fix map offsets in relocation tip-bot for Joe Stringer <tipbot@zytor.com> - 2017-01-26 16:40 +0100
  [PATCHv2 perf/core 3/7] tools lib bpf: Add set/is helpers for all prog types Joe Stringer <joe@ovn.org> - 2017-01-23 02:20 +0100
    [tip:perf/core] tools lib bpf: Add set/is helpers for all prog  types tip-bot for Joe Stringer <tipbot@zytor.com> - 2017-01-26 16:40 +0100
  [PATCHv2 perf/core 2/7] tools lib bpf: Define prog_type fns with macro Joe Stringer <joe@ovn.org> - 2017-01-23 02:20 +0100
    [tip:perf/core] tools lib bpf: Define prog_type fns with macro tip-bot for Joe Stringer <tipbot@zytor.com> - 2017-01-26 16:40 +0100
  Re: [PATCHv2 perf/core 0/7] Libbpf improvements Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-24 17:20 +0100
    Re: [PATCHv2 perf/core 0/7] Libbpf improvements Joe Stringer <joe@ovn.org> - 2017-01-25 02:00 +0100

csiph-web