From patchwork Thu Dec 17 05:23:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 58520 Delivered-To: patch@linaro.org Received: by 10.112.89.199 with SMTP id bq7csp151885lbb; Wed, 16 Dec 2015 21:23:56 -0800 (PST) X-Received: by 10.98.32.77 with SMTP id g74mr11495804pfg.33.1450329836523; Wed, 16 Dec 2015 21:23:56 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si9915220pfa.124.2015.12.16.21.23.56; Wed, 16 Dec 2015 21:23:56 -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; 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 S966467AbbLQFXs (ORCPT + 29 others); Thu, 17 Dec 2015 00:23:48 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:11444 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932169AbbLQFXq (ORCPT ); Thu, 17 Dec 2015 00:23:46 -0500 Received: from 172.24.1.48 (EHLO szxeml428-hub.china.huawei.com) ([172.24.1.48]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BSX91263; Thu, 17 Dec 2015 13:23:37 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml428-hub.china.huawei.com (10.82.67.183) with Microsoft SMTP Server id 14.3.235.1; Thu, 17 Dec 2015 13:23:25 +0800 From: Wang Nan To: , , , , , , , , , , , CC: , , Wang Nan , Wang Nan Subject: [PATCH 07/10] bpf tools: Support BPF_OBJ_PIN and BPF_OBJ_GET Date: Thu, 17 Dec 2015 05:23:11 +0000 Message-ID: <1450329794-161948-8-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1450329794-161948-1-git-send-email-wangnan0@huawei.com> References: <1450329794-161948-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020205.567246DB.0069, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 1e95eb90ff7f52d828460277bd3f59a7 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit b2197755b2633e164a439682fb05a9b5ea48f706 ("bpf: add support for persistent maps/progs") introduces two new operations to both map and program. This patch makes libbpf support it. Signed-off-by: Wang Nan Cc: Alexei Starovoitov Cc: Arnaldo Carvalho de Melo Cc: Daniel Borkmann --- tools/lib/bpf/bpf.c | 21 +++++++++++++++++++++ tools/lib/bpf/bpf.h | 3 +++ 2 files changed, 24 insertions(+) -- 1.8.3.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 89c9d0b..5f174c6 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -129,3 +129,24 @@ int bpf_map_get_next_key(int fd, void *key, void *next_key) return sys_bpf(BPF_MAP_GET_NEXT_KEY, &attr, sizeof(attr)); } + +int bpf_pin_object(int fd, const char *pathname) +{ + union bpf_attr attr; + + bzero(&attr, sizeof(attr)); + attr.pathname = ptr_to_u64((void *)pathname); + attr.bpf_fd = fd; + + return sys_bpf(BPF_OBJ_PIN, &attr, sizeof(attr)); +} + +int bpf_get_pinned_object(const char *pathname) +{ + union bpf_attr attr; + + bzero(&attr, sizeof(attr)); + attr.pathname = ptr_to_u64((void *)pathname); + + return sys_bpf(BPF_OBJ_GET, &attr, sizeof(attr)); +} diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 3d22048..c9f1a1c 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -27,4 +27,7 @@ int bpf_map_update_elem(int fd, void *key, void *value, int bpf_map_lookup_elem(int fd, void *key, void *value); int bpf_map_delete_elem(int fd, void *key); int bpf_map_get_next_key(int fd, void *key, void *next_key); + +int bpf_pin_object(int fd, const char *pathname); +int bpf_get_pinned_object(const char *pathname); #endif