From patchwork Fri Nov 9 00:22:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 10675175 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E01E613BF for ; Fri, 9 Nov 2018 00:22:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1F3F2E904 for ; Fri, 9 Nov 2018 00:22:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C602C2E94F; Fri, 9 Nov 2018 00:22:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FF6C2E91D for ; Fri, 9 Nov 2018 00:22:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727758AbeKIKAc (ORCPT ); Fri, 9 Nov 2018 05:00:32 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:39550 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727751AbeKIKAb (ORCPT ); Fri, 9 Nov 2018 05:00:31 -0500 Received: by mail-pf1-f194.google.com with SMTP id n11-v6so65309pfb.6 for ; Thu, 08 Nov 2018 16:22:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fomichev-me.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KGu9IG6X9Z/NFbeZi3OX9Sg2BFdKzD9qqa8cgkVVrq4=; b=n9AC2+uah8COv5B0M1y4bHguij2SsThBVTRydeNgoQiqVL3axA6+UOdVyzJic/WE2W CO2M2Ox6tfL3e7FlQsZTI9EPWMlm1S2pKtAvW78mRTq0ZwGHa1wRwR/A4L/RM7GfwHQ6 X9fNA7ROhpo/qEBBE25SqBuvPvRoJJiVHEAVBpRtjMknHPqKgjj+YTI5ORb0zD0uvehr 5gHzNSs+b7Nvs3lfS/tNtfEtLWR1Yi4FNuE1/bcDj2au5fTrENdIHf8LynlJCsgCqSx1 KYq6VJ1S0zFI6SF1CKdq2i7bg1rCsv8Jd7P58vQSbUqHmqv/oSgq3++b2TH9orCrvAFe jmwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KGu9IG6X9Z/NFbeZi3OX9Sg2BFdKzD9qqa8cgkVVrq4=; b=fimDONxJcVOJ4gKQd0jWw/yiHw680eA34ylACxKBo73eH0N3RCC4LU9V0ZK72GKP1F jLu7B0GIThsAthgvsZVgsNv7QWG3AQLCrab10quVJGg/HjNsIRJGQM7c/bmc8796ap4Q sbOnlefFra4DMSClCAee6hy2kfLzUNbLRW+EDRzHqXwi2Ayej9fI6Ae5U++9vz+//Yt0 nWUFAO7JyA12gDOCnGAA5Y/rZDZig9EVmDOerlCX4uK2XXT9GRcYSWPA6FqJcbaeg8Ok jTY7xlNvaIAqIe7aD3/O/7TTEFHbqQszb4ngfbi0nFwAgl6tWTyjeestwFGz+zvjUUGJ KCnA== X-Gm-Message-State: AGRZ1gIJw9aNzPeO2yuOkF0gvbVp92Vb4+lad4WXIfuqg/jgT6ZnS4dS BaahaKzTC0vSvO7OdtOLnDzc1g== X-Google-Smtp-Source: AJdET5cpogEZ9aHdhcdrOhYBV6pdrQR5e3zy40EJpYa9u9zQfDukVOeCX3VUslYGW5wK11PDTICp4g== X-Received: by 2002:a62:1552:: with SMTP id 79-v6mr6656360pfv.120.1541722947213; Thu, 08 Nov 2018 16:22:27 -0800 (PST) Received: from mini-arch.hsd1.ca.comcast.net (c-98-210-199-22.hsd1.ca.comcast.net. [98.210.199.22]) by smtp.gmail.com with ESMTPSA id g21-v6sm4918955pgh.82.2018.11.08.16.22.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 16:22:26 -0800 (PST) From: Stanislav Fomichev X-Google-Original-From: Stanislav Fomichev To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, shuah@kernel.org, jakub.kicinski@netronome.com, quentin.monnet@netronome.com Cc: guro@fb.com, jiong.wang@netronome.com, sdf@google.com, bhole_prashant_q7@lab.ntt.co.jp, john.fastabend@gmail.com, jbenc@redhat.com, treeze.taeung@gmail.com, yhs@fb.com, osk@fb.com, sandipan@linux.vnet.ibm.com Subject: [PATCH v4 bpf-next 6/7] bpftool: add pinmaps argument to the load/loadall Date: Thu, 8 Nov 2018 16:22:12 -0800 Message-Id: <20181109002213.5914-7-s@fomichev.me> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181109002213.5914-1-s@fomichev.me> References: <20181109002213.5914-1-s@fomichev.me> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Stanislav Fomichev This new additional argument lets users pin all maps from the object at specified path. Signed-off-by: Stanislav Fomichev Acked-by: Jakub Kicinski --- .../bpftool/Documentation/bpftool-prog.rst | 4 +++- tools/bpf/bpftool/bash-completion/bpftool | 3 ++- tools/bpf/bpftool/prog.c | 24 ++++++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tools/bpf/bpftool/Documentation/bpftool-prog.rst b/tools/bpf/bpftool/Documentation/bpftool-prog.rst index d943d9b67a1d..b04c4a365739 100644 --- a/tools/bpf/bpftool/Documentation/bpftool-prog.rst +++ b/tools/bpf/bpftool/Documentation/bpftool-prog.rst @@ -80,7 +80,7 @@ DESCRIPTION contain a dot character ('.'), which is reserved for future extensions of *bpffs*. - **bpftool prog { load | loadall }** *OBJ* *FILE* [**type** *TYPE*] [**map** {**idx** *IDX* | **name** *NAME*} *MAP*] [**dev** *NAME*] + **bpftool prog { load | loadall }** *OBJ* *FILE* [**type** *TYPE*] [**map** {**idx** *IDX* | **name** *NAME*} *MAP*] [**dev** *NAME*] [**pinmaps** *MAP_DIR*] Load bpf program(s) from binary *OBJ* and pin as *FILE*. Both **bpftool prog load** and **bpftool prog loadall** load all maps and programs from the *OBJ* and differ only in @@ -98,6 +98,8 @@ DESCRIPTION use, referring to it by **id** or through a **pinned** file. If **dev** *NAME* is specified program will be loaded onto given networking device (offload). + Optional **pinmaps** argument can be provided to pin all + maps under *MAP_DIR* directory. Note: *FILE* must be located in *bpffs* mount. It must not contain a dot character ('.'), which is reserved for future diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool index 780ebafb756a..a05d0071f39f 100644 --- a/tools/bpf/bpftool/bash-completion/bpftool +++ b/tools/bpf/bpftool/bash-completion/bpftool @@ -346,7 +346,7 @@ _bpftool() _bpftool_get_map_ids return 0 ;; - pinned) + pinned|pinmaps) _filedir return 0 ;; @@ -358,6 +358,7 @@ _bpftool() COMPREPLY=( $( compgen -W "map" -- "$cur" ) ) _bpftool_once_attr 'type' _bpftool_once_attr 'dev' + _bpftool_once_attr 'pinmaps' return 0 ;; esac diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index 751a90ccfdab..4654d9450cd9 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -802,6 +802,7 @@ static int load_with_options(int argc, char **argv, bool first_prog_only) struct map_replace *map_replace = NULL; struct bpf_program *prog = NULL, *pos; unsigned int old_map_fds = 0; + const char *pinmaps = NULL; struct bpf_object *obj; struct bpf_map *map; const char *pinfile; @@ -906,6 +907,13 @@ static int load_with_options(int argc, char **argv, bool first_prog_only) goto err_free_reuse_maps; } NEXT_ARG(); + } else if (is_prefix(*argv, "pinmaps")) { + NEXT_ARG(); + + if (!REQ_ARGS(1)) + goto err_free_reuse_maps; + + pinmaps = GET_ARG(); } else { p_err("expected no more arguments, 'type', 'map' or 'dev', got: '%s'?", *argv); @@ -1026,6 +1034,14 @@ static int load_with_options(int argc, char **argv, bool first_prog_only) } } + if (pinmaps) { + err = bpf_object__pin_maps(obj, pinmaps); + if (err) { + p_err("failed to pin all maps"); + goto err_unpin; + } + } + if (json_output) jsonw_null(json_wtr); @@ -1036,6 +1052,11 @@ static int load_with_options(int argc, char **argv, bool first_prog_only) return 0; +err_unpin: + if (first_prog_only) + unlink(pinfile); + else + bpf_object__unpin_programs(obj, pinfile); err_close_obj: bpf_object__close(obj); err_free_reuse_maps: @@ -1069,7 +1090,8 @@ static int do_help(int argc, char **argv) " %s %s pin PROG FILE\n" " %s %s { load | loadall } OBJ FILE \\\n" " [type TYPE] [dev NAME] \\\n" - " [map { idx IDX | name NAME } MAP]\n" + " [map { idx IDX | name NAME } MAP]\\\n" + " [pinmaps MAP_DIR]\n" " %s %s attach PROG ATTACH_TYPE MAP\n" " %s %s detach PROG ATTACH_TYPE MAP\n" " %s %s help\n"