Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752717AbbFZOQ5 (ORCPT ); Fri, 26 Jun 2015 10:16:57 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:60819 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752533AbbFZOQz (ORCPT ); Fri, 26 Jun 2015 10:16:55 -0400 From: Wang Nan To: , , , , , , , , , , CC: , , , , Subject: [RFC PATCH v9 21/50] bpf tools: Introduce accessors for struct bpf_object Date: Fri, 26 Jun 2015 14:15:26 +0000 Message-ID: <1435328155-87115-22-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1435328155-87115-1-git-send-email-wangnan0@huawei.com> References: <1435328155-87115-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.197.210] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.558D5EC7.014A,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: 709c38669fe86c8be68c20e27ff0da60 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1578 Lines: 52 This patch add an accessor which allows caller to get count of programs in an object file. Signed-off-by: Wang Nan Acked-by: Alexei Starovoitov --- tools/lib/bpf/libbpf.c | 9 +++++++++ tools/lib/bpf/libbpf.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index e4c5f07..1c210fb 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -936,6 +936,15 @@ void bpf_object__close(struct bpf_object *obj) free(obj); } +int bpf_object__get_prog_cnt(struct bpf_object *obj, size_t *pcnt) +{ + if (!obj || !pcnt) + return -EINVAL; + + *pcnt = obj->nr_programs; + return 0; +} + struct bpf_program * bpf_program__next(struct bpf_program *prev, struct bpf_object *obj) { diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 9e0e102..a20ae2e 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -35,6 +35,9 @@ void bpf_object__close(struct bpf_object *object); int bpf_object__load(struct bpf_object *obj); int bpf_object__unload(struct bpf_object *obj); +/* Accessors of bpf_object */ +int bpf_object__get_prog_cnt(struct bpf_object *obj, size_t *pcnt); + /* Accessors of bpf_program. */ struct bpf_program; struct bpf_program *bpf_program__next(struct bpf_program *prog, -- 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/