From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stanislav Fomichev 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 Message-ID: <20181120231510.46332-2-sdf@google.com> References: <20181120230445.os6ikxaqhq777xao@ast-mbp.dhcp.thefacebook.com> <20181120231510.46332-1-sdf@google.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Cc: daniel@iogearbox.net, Stanislav Fomichev To: netdev@vger.kernel.org, ast@kernel.org Return-path: Received: from mail-ot1-f73.google.com ([209.85.210.73]:51162 "EHLO mail-ot1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725889AbeKUJq4 (ORCPT ); Wed, 21 Nov 2018 04:46:56 -0500 Received: by mail-ot1-f73.google.com with SMTP id j15so2033175ota.17 for ; Tue, 20 Nov 2018 15:15:16 -0800 (PST) In-Reply-To: <20181120231510.46332-1-sdf@google.com> Sender: netdev-owner@vger.kernel.org List-ID: 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 --- 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