From: Stanislav Fomichev <sdf@google.com>
To: netdev@vger.kernel.org, ast@kernel.org
Cc: daniel@iogearbox.net, Stanislav Fomichev <sdf@google.com>
Subject: [PATCH bpf-next v2 2/2] bpf: libbpf: move map name retry into libbpf.c
Date: Tue, 20 Nov 2018 15:15:10 -0800 [thread overview]
Message-ID: <20181120231510.46332-2-sdf@google.com> (raw)
In-Reply-To: <20181120231510.46332-1-sdf@google.com>
To be in line with the previous commit ("bpf: libbpf: retry program
creation without the name"), do the retry at the higher level, not the
syscall level.
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
tools/lib/bpf/bpf.c | 11 +----------
tools/lib/bpf/libbpf.c | 11 +++++++++++
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 836447bb4f14..ce1822194590 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -69,7 +69,6 @@ int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr)
{
__u32 name_len = create_attr->name ? strlen(create_attr->name) : 0;
union bpf_attr attr;
- int ret;
memset(&attr, '\0', sizeof(attr));
@@ -87,15 +86,7 @@ int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr)
attr.map_ifindex = create_attr->map_ifindex;
attr.inner_map_fd = create_attr->inner_map_fd;
- ret = sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
- if (ret < 0 && errno == EINVAL && create_attr->name) {
- /* Retry the same syscall, but without the name.
- * Pre v4.14 kernels don't support map names.
- */
- memset(attr.map_name, 0, sizeof(attr.map_name));
- return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
- }
- return ret;
+ return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
}
int bpf_create_map_node(enum bpf_map_type map_type, const char *name,
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 2ea14dfa28fc..c081b5b8f68f 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1184,6 +1184,17 @@ bpf_object__create_maps(struct bpf_object *obj)
*pfd = bpf_create_map_xattr(&create_attr);
}
+ if (*pfd < 0 && errno == EINVAL && create_attr.name) {
+ /* Retry the same operation, but without the name.
+ * Pre v4.14 kernels don't support map names.
+ */
+ cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
+ pr_warning("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without name.\n",
+ map->name, cp, errno);
+ create_attr.name = NULL;
+ *pfd = bpf_create_map_xattr(&create_attr);
+ }
+
if (*pfd < 0) {
size_t j;
--
2.19.1.1215.g8438c0b245-goog
next prev parent reply other threads:[~2018-11-21 9:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-20 0:46 [PATCH bpf-next] bpf: libbpf: retry program creation without the name Stanislav Fomichev
2018-11-20 1:24 ` Y Song
2018-11-20 19:51 ` Alexei Starovoitov
2018-11-20 21:19 ` Stanislav Fomichev
2018-11-20 23:04 ` Alexei Starovoitov
2018-11-20 23:15 ` [PATCH bpf-next v2 1/2] " Stanislav Fomichev
2018-11-20 23:15 ` Stanislav Fomichev [this message]
2018-11-20 23:18 ` [PATCH bpf-next] " Daniel Borkmann
2018-11-20 23:20 ` Alexei Starovoitov
2018-11-20 23:26 ` Stanislav Fomichev
2018-11-21 2:49 ` Quentin Monnet
2018-11-21 17:28 ` Stanislav Fomichev
2018-11-23 10:51 ` Quentin Monnet
2018-11-26 19:08 ` Vlad Dumitrescu
2018-11-26 19:45 ` Quentin Monnet
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=20181120231510.46332-2-sdf@google.com \
--to=sdf@google.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=netdev@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.