Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp94924rwr; Wed, 26 Apr 2023 21:21:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5dlpJewT1jvAst7LDS9jvORfzY5Eii0FAv1vHonOukZ3eWzG6viJJuHncheqWQR9PlE6Pc X-Received: by 2002:a17:903:283:b0:1a6:a375:cb49 with SMTP id j3-20020a170903028300b001a6a375cb49mr176437plr.39.1682569260995; Wed, 26 Apr 2023 21:21:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682569260; cv=none; d=google.com; s=arc-20160816; b=WK11rmDMRvieBpKc8kxfJrCZO/fDsU9MTD1wyZsqncf/tweMj2/F6+5+zJTY0NnA4H 9Kd6J8swg01DNjyvEVMtBm1bSiT3aWElrqDT54rOdZiM17j1098FUkePylqQq3lvWJo1 +mjzLkPkD6dzylAX9+RReIvL8F5GYYlNTnhHspEL/7ibxVkNz6fipXe1DbsCQ6z6dCDm 5IpfCj7nMKY0mWnRLtd2zJeNJOtX8QhQraYegVK0ZcOcPbGOYmAoFoGYLLgZngko0fRd LY5P/km50QHTcOS/FAcVJKYhjh8DdgYg/h5TnYVWEliyWibyfyJ9dvnE6PdVmda/UQ+J sh3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=NjHmeX5/5YWb0KrtA8dXibV4xoGQyqlvMwQ9oeLChCY=; b=aDjZS5e47ryyXoXmWRezXHo0PlFhEXpQz+jEStWwOB1kGscDv/0CDi3ahdyw8RNg5m axAnhTDpNLwX3j9k4RSPvcn2hb6m4y5CCRTgYYgnjTQ7UYH/Yzv3D5eQ+HaBXjhAatvO tTD0nrFuC0MFlsM4ntQDeva3OZuu5Xonr7qhhu5voNJtXIJS0QPxsE/4lNwU89I2N5OR 6pTHuY56KNH3eIlKtoej+z3Fvj1w0vUSo4Q4DPGztI2qyyJKD2dIjCbEkJId7u8FJRiV LAwntBXuophc6bu5MVPCIvlZ9pSBRcci+Me2uJb37PlEtCQ8FwPKWFVNwGAD3RO3nkNg Yf0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kuroa.me header.s=sig1 header.b=VU18TfG5; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n5-20020a170902f60500b001a994803b1csi4636348plg.19.2023.04.26.21.20.49; Wed, 26 Apr 2023 21:21:00 -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=@kuroa.me header.s=sig1 header.b=VU18TfG5; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242796AbjD0EUJ (ORCPT + 99 others); Thu, 27 Apr 2023 00:20:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229605AbjD0EUF (ORCPT ); Thu, 27 Apr 2023 00:20:05 -0400 Received: from pv50p00im-hyfv10021501.me.com (pv50p00im-hyfv10021501.me.com [17.58.6.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D7A430C0 for ; Wed, 26 Apr 2023 21:20:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kuroa.me; s=sig1; t=1682569202; bh=NjHmeX5/5YWb0KrtA8dXibV4xoGQyqlvMwQ9oeLChCY=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=VU18TfG5f9ZdE26XAq2zd6ihTzH+IswvT0GYWeL6BPiqSUlFRflzbuqhlzT/adX4G B51mAeNYOkZ1UwMNTtudbVGtBgHoTSy9sfd36RucKTqYkRJ0+nl9Jr0tY4dtIV131T TsVAA13YW8G4xdU39lvFITWGysWmRUyTgLkH18Al5mUnXgX6gshXbvHSNQ+lpb6l0h O1VeC12ekhawLzztiZ8QR2v6g3aCq0/z8gU9/MQisJVuUUKXDaD/UsbqSYQ4V/N3DC uPM4njGYPJWjDcmfZwQ9fitbMNgrtnaGhDLy0wI6OaUzv+XlvvknTFRl/De39hwp9r Q8d8XxKZMRi+A== Received: from localhost.localdomain (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-hyfv10021501.me.com (Postfix) with ESMTPSA id 95FB32C0283; Thu, 27 Apr 2023 04:19:57 +0000 (UTC) From: Xueming Feng To: Quentin Monnet Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Xueming Feng Subject: [PATCH bpf-next v3] bpftool: Dump map id instead of value for map_of_maps types Date: Thu, 27 Apr 2023 12:19:49 +0800 Message-Id: <20230427041949.93752-1-kuro@kuroa.me> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: eUiaztbSIHcM1W_QfcSb9ixks5qo62A- X-Proofpoint-ORIG-GUID: eUiaztbSIHcM1W_QfcSb9ixks5qo62A- X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.517,18.0.572,17.11.64.514.0000000_definitions?= =?UTF-8?Q?=3D2022-06-21=5F01:2022-06-21=5F01,2020-02-14=5F11,2022-02-23?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 suspectscore=0 bulkscore=0 clxscore=1030 mlxlogscore=999 malwarescore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2304270037 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 When using `bpftool map dump` with map_of_maps, it is usually more convenient to show the inner map id instead of raw value. We are changing the plain print behavior to show inner_map_id instead of hex value, this would help with quick look up of inner map with `bpftool map dump id `. To avoid disrupting scripted behavior, we will add a new `inner_map_id` field to json output instead of replacing value. plain print: ``` $ bpftool map dump id 138 Without Patch: key: fc 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 27 16 06 00 value: 8b 00 00 00 Found 1 element With Patch: key: fc 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 27 16 06 00 inner_map_id: 139 Found 1 element ``` json print: ``` $ bpftool -p map dump id 567 Without Patch: [{ "key": ["0xc0","0x00","0x02","0x05","0x27","0x16","0x06","0x00" ], "value": ["0x38","0x02","0x00","0x00" ] } ] With Patch: [{ "key": ["0xc0","0x00","0x02","0x05","0x27","0x16","0x06","0x00" ], "value": ["0x38","0x02","0x00","0x00" ], "inner_map_id": 568 } ] ``` Signed-off-by: Xueming Feng --- Changes in v3: - In plain print, use printf() directly since inner map id is always a 32bit int. - Remove unused print_uint() function. - Rename `id` to `inner_map_id` in plain print output for clearness. - Add a new `inner_map_id` field to json output. - Add example output to commit message. Changes in v2: - Fix commit message grammar. - Change `print_uint` to only print to stdout, make `arg` const, and rename `n` to `arg_size`. - Make `print_uint` able to take any size of argument up to `unsigned long`, and print it as unsigned decimal. Sorry for taking this long, my compiling machine is acting weird. And thanks for the reviews and suggestions! tools/bpf/bpftool/map.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c index aaeb8939e137..afcd8455db74 100644 --- a/tools/bpf/bpftool/map.c +++ b/tools/bpf/bpftool/map.c @@ -139,6 +139,10 @@ static void print_entry_json(struct bpf_map_info *info, unsigned char *key, print_hex_data_json(key, info->key_size); jsonw_name(json_wtr, "value"); print_hex_data_json(value, info->value_size); + if (map_is_map_of_maps(info->type)) { + jsonw_uint_field(json_wtr, "inner_map_id", + *(unsigned int *)value); + } if (btf) { struct btf_dumper d = { .btf = btf, @@ -259,8 +263,13 @@ static void print_entry_plain(struct bpf_map_info *info, unsigned char *key, } if (info->value_size) { - printf("value:%c", break_names ? '\n' : ' '); - fprint_hex(stdout, value, info->value_size, " "); + if (map_is_map_of_maps(info->type)) { + printf("inner_map_id:%c", break_names ? '\n' : ' '); + printf("%u ", *(unsigned int *)value); + } else { + printf("value:%c", break_names ? '\n' : ' '); + fprint_hex(stdout, value, info->value_size, " "); + } } printf("\n"); -- 2.37.1 (Apple Git-137.1)