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=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 93DADC43461 for ; Wed, 9 Sep 2020 08:19:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F4CF208FE for ; Wed, 9 Sep 2020 08:19:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=isovalent-com.20150623.gappssmtp.com header.i=@isovalent-com.20150623.gappssmtp.com header.b="oTUiET38" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728214AbgIIITl (ORCPT ); Wed, 9 Sep 2020 04:19:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726060AbgIIITk (ORCPT ); Wed, 9 Sep 2020 04:19:40 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 237C5C061573 for ; Wed, 9 Sep 2020 01:19:40 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id c18so1897413wrm.9 for ; Wed, 09 Sep 2020 01:19:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=3Oevd7iVtCDsmoMCjCDsQDgHNREENuQUSSMZLjv8SJY=; b=oTUiET38UXprPQVuamW2Qi51yJm2OStVaxWSwfBBZrM+OIrPco4rVDJOpW9ZebC1tW 0hfWTkvnGQMVyVjd0Qoc8YGYw+IIZ4ewIEToCCXcZjRHYQrCYTEo3+Ci2rjGIUhEdsTn jQtyvCa1SzINq+J/VEkhwFFs8WCuv9/Ue8M8mki8LTpu75uRHvLJk7PMIjdi6Z6VqMm/ YVZekZ7m/1aEEYiCf35Wd+DW1ePa34HxPXn4oeQucAbI+OB3O2gLtHfWFliqIDYf9n9g 2Rkm5HaYZzj9vHe5jkVLxx+xeZx5Yjau9MVN4SzXiG81ZIsjpuYflryeyM08rEjE4R5f pgdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=3Oevd7iVtCDsmoMCjCDsQDgHNREENuQUSSMZLjv8SJY=; b=isC8M7p/Dinz2lDQpfTuTaiYUZzCnGjclH2Ttb7IBD1qc5OliJ2emfVPS4fa2bmLFP 3tjaislG8oCgmjrBeQrdK9DBbfijMr+UG2AWbkLEwqY32zrxTEit9VTFsMsxzUwXfy2I y/IqSyxjlgrQ2z80iYAXmF8Wif9sFqsSuM2/rs+weT5a9nUaMe5PyIZei5129E0Ly+h4 GzrF5aq8KR1IaIYPt9Il/KJc+JVUraEyapnFbnhYviU0czysoE2hYTWvOkAA8OeNsllH +jGhtPU3jOKssIr5JrX1ZxpllHgCJbbRo9ZAj0KbUxhHSkJKqrs+D18VGagASqZxOd6Z hHvw== X-Gm-Message-State: AOAM532PGcvtYrrChRcKZQ1FQ/9HTarIzenCI9nR6emHa7GhLo9KYcQj aNsjqOV3N+NJopN5yLUp1wAUOi9KVdpQd6Ai9Xw= X-Google-Smtp-Source: ABdhPJzuIUQ3D0Sn6FNu5ARK7tlponD66y4IQe7I9qqRksdNKM/7Te7pLVhcjZZfgYIPUqoxIj0o2Q== X-Received: by 2002:adf:cc8c:: with SMTP id p12mr2876875wrj.92.1599639578773; Wed, 09 Sep 2020 01:19:38 -0700 (PDT) Received: from [192.168.1.12] ([194.35.119.152]) by smtp.gmail.com with ESMTPSA id s11sm3015593wrt.43.2020.09.09.01.19.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 09 Sep 2020 01:19:38 -0700 (PDT) Subject: Re: [PATCH bpf-next v2 1/2] tools: bpftool: clean up function to dump map entry To: Andrii Nakryiko Cc: Alexei Starovoitov , Daniel Borkmann , bpf , Networking References: <20200907163634.27469-1-quentin@isovalent.com> <20200907163634.27469-2-quentin@isovalent.com> From: Quentin Monnet Message-ID: Date: Wed, 9 Sep 2020 09:19:37 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On 09/09/2020 04:25, Andrii Nakryiko wrote: > On Mon, Sep 7, 2020 at 9:36 AM Quentin Monnet wrote: >> >> The function used to dump a map entry in bpftool is a bit difficult to >> follow, as a consequence to earlier refactorings. There is a variable >> ("num_elems") which does not appear to be necessary, and the error >> handling would look cleaner if moved to its own function. Let's clean it >> up. No functional change. >> >> v2: >> - v1 was erroneously removing the check on fd maps in an attempt to get >> support for outer map dumps. This is already working. Instead, v2 >> focuses on cleaning up the dump_map_elem() function, to avoid >> similar confusion in the future. >> >> Signed-off-by: Quentin Monnet >> --- >> tools/bpf/bpftool/map.c | 101 +++++++++++++++++++++------------------- >> 1 file changed, 52 insertions(+), 49 deletions(-) >> >> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c >> index bc0071228f88..c8159cb4fb1e 100644 >> --- a/tools/bpf/bpftool/map.c >> +++ b/tools/bpf/bpftool/map.c >> @@ -213,8 +213,9 @@ static void print_entry_json(struct bpf_map_info *info, unsigned char *key, >> jsonw_end_object(json_wtr); >> } >> >> -static void print_entry_error(struct bpf_map_info *info, unsigned char *key, >> - const char *error_msg) >> +static void >> +print_entry_error_msg(struct bpf_map_info *info, unsigned char *key, >> + const char *error_msg) >> { >> int msg_size = strlen(error_msg); >> bool single_line, break_names; >> @@ -232,6 +233,40 @@ static void print_entry_error(struct bpf_map_info *info, unsigned char *key, >> printf("\n"); >> } >> >> +static void >> +print_entry_error(struct bpf_map_info *map_info, void *key, int lookup_errno) >> +{ >> + /* For prog_array maps or arrays of maps, failure to lookup the value >> + * means there is no entry for that key. Do not print an error message >> + * in that case. >> + */ > > this is the case when error is ENOENT, all the other ones should be > treated the same, no? Do you mean all map types should be treated the same? If so, I can remove the check below, as in v1. Or do you mean there is a missing check on the error value? In which case I can extend this check to verify we have ENOENT. >> + if (map_is_map_of_maps(map_info->type) || >> + map_is_map_of_progs(map_info->type)) >> + return; >> + >> + if (json_output) { >> + jsonw_start_object(json_wtr); /* entry */ >> + jsonw_name(json_wtr, "key"); >> + print_hex_data_json(key, map_info->key_size); >> + jsonw_name(json_wtr, "value"); >> + jsonw_start_object(json_wtr); /* error */ >> + jsonw_string_field(json_wtr, "error", strerror(lookup_errno)); >> + jsonw_end_object(json_wtr); /* error */ >> + jsonw_end_object(json_wtr); /* entry */ >> + } else { >> + const char *msg = NULL; >> + >> + if (lookup_errno == ENOENT) >> + msg = ""; >> + else if (lookup_errno == ENOSPC && >> + map_info->type == BPF_MAP_TYPE_REUSEPORT_SOCKARRAY) >> + msg = ""; >> + >> + print_entry_error_msg(map_info, key, >> + msg ? : strerror(lookup_errno)); >> + } >> +} >> + > > [...] >