Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2647915imj; Mon, 11 Feb 2019 06:26:25 -0800 (PST) X-Google-Smtp-Source: AHgI3IaYSfxj4XSGeytmAAXG0qo1csWeWJuTR3jBcBdlvKUo0T4A15+ZJ3mjVwfRkGov5olLErb4 X-Received: by 2002:a63:ef4c:: with SMTP id c12mr22308468pgk.84.1549895185063; Mon, 11 Feb 2019 06:26:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549895185; cv=none; d=google.com; s=arc-20160816; b=foLdqu9f/tMTpWW3scNqYDeIu0vhLEh3hYPUNGeJcPC2+oikaFo4ApZaXHHgwLd0PJ FGiU1GCJo5ktD24P1XGHBT0IDP869H0AE4aOyMsbnZG/qHPaKGCWBu8F1F/Oi+vCipZS PbSFb2Bu8d0JFOBvETJ+yLa3P+7uxqn6zgxuIun+oslCesjoXh78VkVk6cC8qEAhOuk9 qmWC7qofaiOB1fP/QmCirI3zwgMtCm2mt5nUPzORACBSzBl/R4mg62LzYdzTCTzel6CG I8G0qBggrvwz2WM59wDYamxrjyk605tVbnZ2Nsa7ohIIcjSN2zb+Mwby2/4YseR7DQAb OCkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=32oZGuIbZqNNGXjQ13cSYqCSdzgnnhrgx/Nv/EMEWPw=; b=yX11zmIIz7JNy66YxSge3Q1Bd06VFzg9w25mOk3jFqXtZGQD88k9Zp7FuQG/fhNr9O CmIZzdlB17TQCxRPHjsYKuNdEQ717WYasKEnW5mmbvcjjhV+UCdccspqZJACx36qbIU9 ulF7EDSVXr+zEvFL1aFjd4VBXwFkej519/jtr5J0kXqrVdEL1/p+Z7EoDgqs5eMj9xwf Gdn6JLrdTW20AjTN+pzl19oHURKZKsO1DpDQCvSQ5t7Z7cLbJc1u6mA13mTkm9EcXNmA lZmuvDvZLWCev0KIubDP+6L1u9OR3dk72Mmi1iEl8LBI4bI7EOxPlbbnAqj0vrxSHiga LEPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NKYEQ0BF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33si10347813plt.228.2019.02.11.06.26.09; Mon, 11 Feb 2019 06:26:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NKYEQ0BF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728586AbfBKOVo (ORCPT + 99 others); Mon, 11 Feb 2019 09:21:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:54534 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728572AbfBKOVn (ORCPT ); Mon, 11 Feb 2019 09:21:43 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A7C8720838; Mon, 11 Feb 2019 14:21:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549894902; bh=p0OEtxHDZiIjgC1wAPZL0XDuJ8LyaC9OCyMtjprPqeg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NKYEQ0BF2nfUERXsBYsQ0ZwbzUW4/CmEle0OCMdI/6b8yqmjTVKVkJ0sQph9d1o+7 KZnGlGWGS1hVXd2UIuMDtJhXDRwmenW1T9wGBorpR9mASep89RAGNW7yN9HnorVG6c VKb6Ge8isw8sd8I9+H25yN7Z6azt6BCZ4keDt030= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Ahern , Jakub Kicinski , Daniel Borkmann , Sasha Levin Subject: [PATCH 4.20 027/352] bpftool: Improve handling of ENOENT on map dumps Date: Mon, 11 Feb 2019 15:14:14 +0100 Message-Id: <20190211141848.073427002@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit bf598a8f0f771302d4ecb0ef0003c54732221597 ] bpftool output is not user friendly when dumping a map with only a few populated entries: $ bpftool map 1: devmap name tx_devmap flags 0x0 key 4B value 4B max_entries 64 memlock 4096B 2: array name tx_idxmap flags 0x0 key 4B value 4B max_entries 64 memlock 4096B $ bpftool map dump id 1 key: 00 00 00 00 value: No such file or directory key: 01 00 00 00 value: No such file or directory key: 02 00 00 00 value: No such file or directory key: 03 00 00 00 value: 03 00 00 00 Handle ENOENT by keeping the line format sane and dumping "" for the value $ bpftool map dump id 1 key: 00 00 00 00 value: key: 01 00 00 00 value: key: 02 00 00 00 value: key: 03 00 00 00 value: 03 00 00 00 ... Signed-off-by: David Ahern Acked-by: Jakub Kicinski Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- tools/bpf/bpftool/map.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c index 7bf38f0e152e..9988d5c126b6 100644 --- a/tools/bpf/bpftool/map.c +++ b/tools/bpf/bpftool/map.c @@ -383,7 +383,10 @@ static void print_entry_plain(struct bpf_map_info *info, unsigned char *key, printf(single_line ? " " : "\n"); printf("value:%c", break_names ? '\n' : ' '); - fprint_hex(stdout, value, info->value_size, " "); + if (value) + fprint_hex(stdout, value, info->value_size, " "); + else + printf(""); printf("\n"); } else { @@ -398,8 +401,11 @@ static void print_entry_plain(struct bpf_map_info *info, unsigned char *key, for (i = 0; i < n; i++) { printf("value (CPU %02d):%c", i, info->value_size > 16 ? '\n' : ' '); - fprint_hex(stdout, value + i * step, - info->value_size, " "); + if (value) + fprint_hex(stdout, value + i * step, + info->value_size, " "); + else + printf(""); printf("\n"); } } @@ -731,7 +737,11 @@ static int dump_map_elem(int fd, void *key, void *value, jsonw_string_field(json_wtr, "error", strerror(lookup_errno)); jsonw_end_object(json_wtr); } else { - print_entry_error(map_info, key, strerror(lookup_errno)); + if (errno == ENOENT) + print_entry_plain(map_info, key, NULL); + else + print_entry_error(map_info, key, + strerror(lookup_errno)); } return 0; -- 2.19.1