From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6978EC2D0A8 for ; Tue, 29 Sep 2020 03:30:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1AF3B207C4 for ; Tue, 29 Sep 2020 03:30:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="evrjgEC9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726961AbgI2Day (ORCPT ); Mon, 28 Sep 2020 23:30:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726396AbgI2Day (ORCPT ); Mon, 28 Sep 2020 23:30:54 -0400 Received: from mail-yb1-xb44.google.com (mail-yb1-xb44.google.com [IPv6:2607:f8b0:4864:20::b44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 225FFC061755; Mon, 28 Sep 2020 20:30:54 -0700 (PDT) Received: by mail-yb1-xb44.google.com with SMTP id 133so2538231ybg.11; Mon, 28 Sep 2020 20:30:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sLMvUto+o6tyT6B9ZRGNVB2YVLrE5KRP5IeJEFWRrVk=; b=evrjgEC9T2TBp4OG9ZHlhkiaN7SjPl+8msoGuXbMvIbVdoagqucfatI/4tNIU+UwUH LdRYfkM9Fz8ostuZYq+c8f+H9umKDwnMR6Q2JD3eQ1FWd/2piiHSd55S8SaIsrDue9pg NuOfDMr9i+O8ZJfwqdk5Jzu8ZrkvSlqBSyYWKLEVUurg3a+K3g7/nS+tKe+RQlU0aEQ4 MWZeDmefygeYQxgk8Igd0YQ2RnKdseqYJx4pm+6L6M5WuOzsvL9O6K9TM8GXjXtIgzMJ ZT9LUmYNZ6wTvIpmeF/v9vYgE9jPsAsnPzNziL6Sn7CRjN1euiZW1ctlbFCVBjf8WHHh bLig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sLMvUto+o6tyT6B9ZRGNVB2YVLrE5KRP5IeJEFWRrVk=; b=F9nMCvRLlpYHvzRxYFYZzuDCBX+UiD0WpRVZi04IFrxH65nn602DcK+IkjsnW7ewUI GOY+iNcOS5RqK7eGQJSo753qvF4PghQSZdSEtqvuCa/f5s2P36ezBj0abO1rLUQ3JSas EXmqT3zWPBIZerwXZsiEd4h2nde4XjplyCq2h2NRfF+C7vsEjwJVbp3KnLjS3+esieTy MEMVdjdD7kXzjShXW41f5AWzTxhII4PXlwHabm27i4JKa0un7gtSTlVLDivBqMGUS1uK 0jlEWBpdkbam6xoVxrXcsp+JSiwwfpQEeDlnCixukWnWBl7MH0hHtAwz10zSuAKwXwqC yJZw== X-Gm-Message-State: AOAM532Uwd15cG7I/D7w7FtP7RadKqR+JlOcFEAmFZqTyGWJORFmd5g5 16aPgXMh1364DCbB7Hm9rPZKBCridxOjJmQ7W950RVANhbnS3Q== X-Google-Smtp-Source: ABdhPJyVm5aNMEvKYxK7dLXQRcqaxzmSeuC4HldFxCrm8WF8Gc/PzxeVMC7w0MjyBuppHJjSax6BmJTXvugNWJunqfM= X-Received: by 2002:a25:6644:: with SMTP id z4mr3539545ybm.347.1601350253272; Mon, 28 Sep 2020 20:30:53 -0700 (PDT) MIME-Version: 1.0 References: <20200929031845.751054-1-liuhangbin@gmail.com> In-Reply-To: <20200929031845.751054-1-liuhangbin@gmail.com> From: Andrii Nakryiko Date: Mon, 28 Sep 2020 20:30:42 -0700 Message-ID: Subject: Re: [PATCH bpf-next] libbpf: export bpf_object__reuse_map() to libbpf api To: Hangbin Liu Cc: bpf , Networking , =?UTF-8?B?VG9rZSBIw7hpbGFuZC1Kw7hyZ2Vuc2Vu?= , Jiri Benc , Jesper Dangaard Brouer , Daniel Borkmann , Alexei Starovoitov , Stephen Hemminger , Song Liu , Yonghong Song Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Mon, Sep 28, 2020 at 8:20 PM Hangbin Liu wrote: > > Besides bpf_map__reuse_fd(), which could let us reuse existing map fd. > bpf_object__reuse_map() could let us reuse existing pinned maps, which > is helpful. > > This functions could also be used when we add iproute2 libbpf support, > so we don't need to re-use or re-implement new functions like > bpf_obj_get()/bpf_map_selfcheck_pinned() in iproute2. > > Signed-off-by: Hangbin Liu > --- > tools/lib/bpf/libbpf.c | 3 +-- > tools/lib/bpf/libbpf.h | 1 + > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 32dc444224d8..e835d7a3437f 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -4033,8 +4033,7 @@ static bool map_is_reuse_compat(const struct bpf_map *map, int map_fd) > map_info.map_flags == map->def.map_flags); > } > > -static int > -bpf_object__reuse_map(struct bpf_map *map) > +int bpf_object__reuse_map(struct bpf_map *map) > { > char *cp, errmsg[STRERR_BUFSIZE]; > int err, pin_fd; > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h > index a750f67a23f6..4b9e615eb393 100644 > --- a/tools/lib/bpf/libbpf.h > +++ b/tools/lib/bpf/libbpf.h > @@ -431,6 +431,7 @@ bpf_map__prev(const struct bpf_map *map, const struct bpf_object *obj); > /* get/set map FD */ > LIBBPF_API int bpf_map__fd(const struct bpf_map *map); > LIBBPF_API int bpf_map__reuse_fd(struct bpf_map *map, int fd); > +LIBBPF_API int bpf_object__reuse_map(struct bpf_map *map); It's internal function, which doesn't check that map->pin_path is set, for one thing. It shouldn't be exposed. libbpf exposes bpf_map__set_pin_path() to set pin_path for any map, and then during load time libbpf with "reuse map", if pin_path is not NULL. Doesn't that work for you? > /* get map definition */ > LIBBPF_API const struct bpf_map_def *bpf_map__def(const struct bpf_map *map); > /* get map name */ > -- > 2.25.4 >