diff options
author | Stanislav Fomichev <sdf@google.com> | 2018-11-09 11:21:42 -0500 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2018-11-10 18:56:10 -0500 |
commit | fd734c5cca62b7630703244d3613be135d646a0e (patch) | |
tree | 0546f050a5173c376a319e7fff09dae12abf535a /tools/lib/bpf/libbpf.c | |
parent | 0c19a9fbc9cdba29c7effb34fd5a97226bf934e6 (diff) |
libbpf: bpf_program__pin: add special case for instances.nr == 1
When bpf_program has only one instance, don't create a subdirectory with
per-instance pin files (<prog>/0). Instead, just create a single pin file
for that single instance. This simplifies object pinning by not creating
unnecessary subdirectories.
This can potentially break existing users that depend on the case
where '/0' is always created. However, I couldn't find any serious
usage of bpf_program__pin inside the kernel tree and I suppose there
should be none outside.
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
-rw-r--r-- | tools/lib/bpf/libbpf.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 341008f47c8a..97ce9f214002 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c | |||
@@ -1761,6 +1761,11 @@ int bpf_program__pin(struct bpf_program *prog, const char *path) | |||
1761 | return -EINVAL; | 1761 | return -EINVAL; |
1762 | } | 1762 | } |
1763 | 1763 | ||
1764 | if (prog->instances.nr == 1) { | ||
1765 | /* don't create subdirs when pinning single instance */ | ||
1766 | return bpf_program__pin_instance(prog, path, 0); | ||
1767 | } | ||
1768 | |||
1764 | err = make_dir(path); | 1769 | err = make_dir(path); |
1765 | if (err) | 1770 | if (err) |
1766 | return err; | 1771 | return err; |
@@ -1823,6 +1828,11 @@ int bpf_program__unpin(struct bpf_program *prog, const char *path) | |||
1823 | return -EINVAL; | 1828 | return -EINVAL; |
1824 | } | 1829 | } |
1825 | 1830 | ||
1831 | if (prog->instances.nr == 1) { | ||
1832 | /* don't create subdirs when pinning single instance */ | ||
1833 | return bpf_program__unpin_instance(prog, path, 0); | ||
1834 | } | ||
1835 | |||
1826 | for (i = 0; i < prog->instances.nr; i++) { | 1836 | for (i = 0; i < prog->instances.nr; i++) { |
1827 | char buf[PATH_MAX]; | 1837 | char buf[PATH_MAX]; |
1828 | int len; | 1838 | int len; |