Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1171414imw; Wed, 13 Jul 2022 15:08:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vykCVHIcwHjOnOhk4Yutj0lJzArIedzKxRWeT6axeU2M8Us5uR36hQPdALZQXl5uYHk4s6 X-Received: by 2002:a05:6a00:1705:b0:525:4cac:fa65 with SMTP id h5-20020a056a00170500b005254cacfa65mr5257219pfc.40.1657750116307; Wed, 13 Jul 2022 15:08:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657750116; cv=none; d=google.com; s=arc-20160816; b=jVfJ/dUrezD0loz+s5Y3G7Z1dOhrPoHqHf5XELUX4O2JUPILzVaaP45h97lVrRK8z4 UDqqDdX1Ukmyo40tFzQem8lCHGx2YTHjS9j4cO/FOhm+vg8ePouiXVl6FzTFQf90coTr FT0CS2pyVwQKLhxoKJPD3g9iJGKEuEFFrNjWy11IGmjvAIFz20hXTilZSLJwFdr9SjHt Z/JEb/zUPcA0fUbFroGN2pSOjmMFC3zh9ex8x13q2f93/XP78P2YGrYsUAiauO2DOphs dukT5ZETbYbVbcgB0wXOBkBOZLgOUqghfGXZcP3Q2xOJ/6wC1LCJaKVxj2cVZZlRqoxQ jgZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KCIFkLMKMpX+Y9w6k09/VmA+FsaqBvsnLjSpd/VlknQ=; b=dL0AC/siU+3AwWEoLM5A7omBt4cRHoRV449TuYom5658b98sDfjtkShA5kQgbMvLwQ FBD+ctZFQNM8+sxsVyvnXwu18RSJ8nVqgbOW2Cfm3RCo63asfvSoD6rOpLBnD1Nuw5ta 8g4Ernc4yIkhyiDmAcjxkoBvl9KH290WDSqLun+TKv8osu9u1epm0U2/Xs2hS1D+MCfa kcdAuDGxsPH+WC2pKX90+rbWVvNGoKALCO4p44/b+GFLPxfaHYa2uX/gLWBps+3vSUuP mYB1CcR80Yit0gZe9/FEoAfyCcDWPcOiqUs9UWwJL2q0rz1YMM5I2cwRmm4LIYWg01Q+ uUiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="cihlpN/v"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nr12-20020a17090b240c00b001efabd2e96bsi3256398pjb.73.2022.07.13.15.08.23; Wed, 13 Jul 2022 15:08:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="cihlpN/v"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236782AbiGMVw2 (ORCPT + 99 others); Wed, 13 Jul 2022 17:52:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236680AbiGMVw1 (ORCPT ); Wed, 13 Jul 2022 17:52:27 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 482BB2DA8D for ; Wed, 13 Jul 2022 14:52:26 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id o15so304369pjh.1 for ; Wed, 13 Jul 2022 14:52:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KCIFkLMKMpX+Y9w6k09/VmA+FsaqBvsnLjSpd/VlknQ=; b=cihlpN/vfaDChG8MTo9W5WeMIOQfXXNWECGHf1HDlDXBYyCjsCAYPeelb9V5ZyOcKg mTPe9mheim3oEAA8uH2+y6eYsBaSw+JMAT0/W0jVXpezPPfTA2KpvtVMWeKd8DsTa2yf +Gspm9hN28/JftaE7+Au2YHp5zUpIZMXo3qsoHjQyqCtaevLrclv3GixxvwFkXUPk0fN YkhgtJljyJ/gN4mMexJ3DkffpNXLsc0ktjcRL4iLC3hIdBEEUyogsW+hKJWlkI0mhNEe XtvUxkqzdrqOF/gdKxbvfw//5KRops9oO6WblxZtcHiGKiqWcjU3lDAV++DoXJI6genB h/TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KCIFkLMKMpX+Y9w6k09/VmA+FsaqBvsnLjSpd/VlknQ=; b=szyPkbgV9lrAowv2yxo2iWKCh6UY99AY7HwyY2jzqk1eG7QgqiLbq4/n/qCxS4VCD8 ubuFkjooGGAj2oWDR4fI+pzrDDS4rSwEUZ7c9/VEvqeolftxG8S8Y6mw2QW5mHoub/uS pGK84Pr/HAITfEBVqAV+Gq/p5c1VAYE1O0k5pXAOB+ePmSPPPcVww9WEKBbpmgiW2ZYK d1KYTm5r+Y1B48IY7Z2flwjxRs381WCx/awbETWrO8TVwbUF4GM/NqnNp0t2BzU/qtLM fUPnWb/KQg/S6AUtwt88bbVBJza+tciSk30+Zq/lSkCiESLo4FMQG6SXvuUimR5lCZNB L3UA== X-Gm-Message-State: AJIora/M/vPX/7n87he+ORALasPEkVJ1AJls9+Z3BKiYStP0chngpPoC p3I5iC/q2T/6afIDGXsnhlZHGCuHIU18DFf4w2mmIw== X-Received: by 2002:a17:90b:4b4d:b0:1ef:bff5:de4f with SMTP id mi13-20020a17090b4b4d00b001efbff5de4fmr12341485pjb.120.1657749145553; Wed, 13 Jul 2022 14:52:25 -0700 (PDT) MIME-Version: 1.0 References: <20220713214246.2545204-1-jevburton.kernel@gmail.com> In-Reply-To: <20220713214246.2545204-1-jevburton.kernel@gmail.com> From: Stanislav Fomichev Date: Wed, 13 Jul 2022 14:52:14 -0700 Message-ID: Subject: Re: [PATCH bpf-next] libbpf: Add bpf_map__set_name() To: Joe Burton Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Joe Burton Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 13, 2022 at 2:43 PM Joe Burton wrote: > > From: Joe Burton > > Add the capability to set a `struct bpf_map` name. > > bpf_map__reuse_fd(struct bpf_map *map, int fd) does the following: > > 1. get the bpf_map_info of the passed-in fd > 2. strdup the name from the bpf_map_info > 3. assign that name to the map > 4. and some other stuff > > While `map.name` may initially be arbitrarily long, this operation > truncates it after 15 characters. > > We have some infrastructure that uses bpf_map__reuse_fd() to preserve > maps across upgrades. Some of our users have long map names, and are > seeing their maps 'disappear' after an upgrade, due to the name > truncation. > > By invoking `bpf_map__set_name()` after `bpf_map__reuse_fd()`, we can > trivially work around the issue. Asked you internally, but not sure I follow. Can you share more on why the following won't fix it for us: https://lore.kernel.org/bpf/OSZP286MB1725CEA1C95C5CB8E7CCC53FB8869@OSZP286MB1725.JPNP286.PROD.OUTLOOK.COM/ ? The idea seems to be to get the supplied map name (from the obj) instead of using pin name? So why is it not enough? > Signed-off-by: Joe Burton > --- > tools/lib/bpf/libbpf.c | 22 ++++++++++++++++++++++ > tools/lib/bpf/libbpf.h | 3 ++- > 2 files changed, 24 insertions(+), 1 deletion(-) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 72548798126b..725baf508e6f 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -9089,6 +9089,28 @@ const char *bpf_map__name(const struct bpf_map *map) > return map->name; > } > > +int bpf_map__set_name(struct bpf_map *map, const char *name) > +{ > + char *new_name; > + > + if (!map) > + return libbpf_err(-EINVAL); > + > + new_name = strdup(name); > + if (!new_name) > + return libbpf_err(-ENOMEM); > + > + if (map_uses_real_name(map)) { > + free(map->real_name); > + map->real_name = new_name; > + } else { > + free(map->name); > + map->name = new_name; > + } > + > + return 0; > +} > + > enum bpf_map_type bpf_map__type(const struct bpf_map *map) > { > return map->def.type; > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h > index e4d5353f757b..e898c4cb514a 100644 > --- a/tools/lib/bpf/libbpf.h > +++ b/tools/lib/bpf/libbpf.h > @@ -731,8 +731,9 @@ LIBBPF_API bool bpf_map__autocreate(const struct bpf_map *map); > */ > LIBBPF_API int bpf_map__fd(const struct bpf_map *map); > LIBBPF_API int bpf_map__reuse_fd(struct bpf_map *map, int fd); > -/* get map name */ > +/* get/set map name */ > LIBBPF_API const char *bpf_map__name(const struct bpf_map *map); > +LIBBPF_API int bpf_map__set_name(struct bpf_map *map, const char *name); > /* get/set map type */ > LIBBPF_API enum bpf_map_type bpf_map__type(const struct bpf_map *map); > LIBBPF_API int bpf_map__set_type(struct bpf_map *map, enum bpf_map_type type); > -- > 2.37.0.144.g8ac04bfd2-goog >