From patchwork Thu Jan 3 18:33:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 1020475 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="T6rCAOkd"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43VxPV2tGZz9s7T for ; Fri, 4 Jan 2019 05:33:18 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726014AbfACSdO (ORCPT ); Thu, 3 Jan 2019 13:33:14 -0500 Received: from mail-io1-f73.google.com ([209.85.166.73]:52581 "EHLO mail-io1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725871AbfACSdO (ORCPT ); Thu, 3 Jan 2019 13:33:14 -0500 Received: by mail-io1-f73.google.com with SMTP id h7so40161320iof.19 for ; Thu, 03 Jan 2019 10:33:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=MGAym+YGFJx0lFMGT4IsvmcnTQwcMxrPg8u3ggBqTRc=; b=T6rCAOkd8ot6ri+t9sLxoB6je8JtZzqSnAnuDEwdvoU5/3+BnfijKdQh4ggSUYgB/6 IOJ4dH8N6PwMwY2tdLOWC7W/8RDRftYRrP60yKVGHkbJ77vTdhLoaKeRpuIEV3tmzbo6 qKkEPYZSZoVBxTZ7kkoPMhveG5TaQbMmMgQ6G2oFmEQiAKkzO9zYFagXq8zYoPFFUnqm en06q/UXH8k4ispKp2BGHRdaWx5oz343ibsIrWt/Ddyh94eWurQZ9+/scccHUu1YEhhO IyOxOOtBheTAmXg+HnO2yQc4rwai++P8RlqBfHb7mfCwKVEYUmWyfxOc82PU2BnDJeBD QSLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=MGAym+YGFJx0lFMGT4IsvmcnTQwcMxrPg8u3ggBqTRc=; b=gu8eqdf5i3lFGE3IyA8WYvBSMK0qQ6pw6BLLJBNtfx7PARxMbuWKxA8qmMEEMRPt+c L1oUqWQRB5h/SzFb0u5PLrgE3C5Y47qmm8EZgateMoAEEBL7jcH6mH1OaLQAeOAT8bvv g8Mtui3pfyrKjJOjZF/KQ5PPfaShanXdUNxhsydGrJTu5AcjLVkMap9VWAZQA7FO9/wI Awwco2NgfOKQ026WIzviY2tIPvRvFNFewhAjSfx1TsTfKuHgZSp2ENwT2CHUzsz8sGgg vsoxCibELq3o65QOP16Ju1iHmcdqhUX3fT2dglKivwHXAxHEBn8sg992vDQLlW0UVlMz vkSA== X-Gm-Message-State: AJcUukffpWl74/5Sdmo3FLzYizA106rmj5jVJ62Rp9mKYBmK5bBKvhEO R8qmmHVCD6j2/ChlgpcR+43kuEAj/UR0uR0P0hP5zzOJxKup/w0kKHPXs542IHdtL8qeH+Q8Uf8 7ZLrlPvcohqKmhiLBt/hVgND+YsRgZ6Q8SMgZfmfBIK3nfESV8A1doA== X-Google-Smtp-Source: ALg8bN7U3i0fE6kOlsqnCD7JR6dMq0j0kK4CT6VNqsSx3R7BApc4WHT8g6e4mQb1HT1RidgDIgZEQD8= X-Received: by 2002:a24:4e4b:: with SMTP id r72mr2286565ita.18.1546540393026; Thu, 03 Jan 2019 10:33:13 -0800 (PST) Date: Thu, 3 Jan 2019 10:33:05 -0800 Message-Id: <20190103183306.232540-1-sdf@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.20.1.415.g653613c723-goog Subject: [PATCH bpf 1/2] bpftool: support queues and stacks in update command From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, ast@kernel.org, daniel@iogearbox.net, jakub.kicinski@netronome.com, quentin.monnet@netronome.com, Stanislav Fomichev Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Bpftool expects both key and value for 'update' operations. For some map types, key should not be specified. Support updating those map types. Before: bpftool map create /sys/fs/bpf/q type queue value 4 entries 10 name q bpftool map update pinned /sys/fs/bpf/q value 0 1 2 3 Error: did not find key After: bpftool map create /sys/fs/bpf/q type queue value 4 entries 10 name q bpftool map update pinned /sys/fs/bpf/q value 0 1 2 3 Signed-off-by: Stanislav Fomichev --- tools/bpf/bpftool/Documentation/bpftool-map.rst | 4 ++-- tools/bpf/bpftool/map.c | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tools/bpf/bpftool/Documentation/bpftool-map.rst b/tools/bpf/bpftool/Documentation/bpftool-map.rst index 64b001b4f777..81842fdf483d 100644 --- a/tools/bpf/bpftool/Documentation/bpftool-map.rst +++ b/tools/bpf/bpftool/Documentation/bpftool-map.rst @@ -25,7 +25,7 @@ MAP COMMANDS | **bpftool** **map create** *FILE* **type** *TYPE* **key** *KEY_SIZE* **value** *VALUE_SIZE* \ | **entries** *MAX_ENTRIES* **name** *NAME* [**flags** *FLAGS*] [**dev** *NAME*] | **bpftool** **map dump** *MAP* -| **bpftool** **map update** *MAP* **key** *DATA* **value** *VALUE* [*UPDATE_FLAGS*] +| **bpftool** **map update** *MAP* [**key** *DATA*] **value** *VALUE* [*UPDATE_FLAGS*] | **bpftool** **map lookup** *MAP* **key** *DATA* | **bpftool** **map getnext** *MAP* [**key** *DATA*] | **bpftool** **map delete** *MAP* **key** *DATA* @@ -62,7 +62,7 @@ DESCRIPTION **bpftool map dump** *MAP* Dump all entries in a given *MAP*. - **bpftool map update** *MAP* **key** *DATA* **value** *VALUE* [*UPDATE_FLAGS*] + **bpftool map update** *MAP* [**key** *DATA*] **value** *VALUE* [*UPDATE_FLAGS*] Update map entry for a given *KEY*. *UPDATE_FLAGS* can be one of: **any** update existing entry diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c index 2037e3dc864b..30b92715248d 100644 --- a/tools/bpf/bpftool/map.c +++ b/tools/bpf/bpftool/map.c @@ -781,11 +781,11 @@ static int do_dump(int argc, char **argv) static int do_update(int argc, char **argv) { + void *key = NULL, *value = NULL; struct bpf_map_info info = {}; __u32 len = sizeof(info); __u32 *value_fd = NULL; __u32 flags = BPF_ANY; - void *key, *value; int fd, err; if (argc < 2) @@ -795,9 +795,16 @@ static int do_update(int argc, char **argv) if (fd < 0) return -1; - key = malloc(info.key_size); + if (info.key_size) { + key = malloc(info.key_size); + if (!key) { + p_err("mem alloc failed"); + err = -1; + goto exit_free; + } + } value = alloc_value(&info); - if (!key || !value) { + if (!value) { p_err("mem alloc failed"); err = -1; goto exit_free; @@ -1135,7 +1142,7 @@ static int do_help(int argc, char **argv) " entries MAX_ENTRIES name NAME [flags FLAGS] \\\n" " [dev NAME]\n" " %s %s dump MAP\n" - " %s %s update MAP key DATA value VALUE [UPDATE_FLAGS]\n" + " %s %s update MAP [key DATA] value VALUE [UPDATE_FLAGS]\n" " %s %s lookup MAP key DATA\n" " %s %s getnext MAP [key DATA]\n" " %s %s delete MAP key DATA\n"