From patchwork Thu Dec 1 18:02:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 86138 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp814773qgi; Thu, 1 Dec 2016 10:06:21 -0800 (PST) X-Received: by 10.99.204.81 with SMTP id q17mr71519813pgi.168.1480615581317; Thu, 01 Dec 2016 10:06:21 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y1si1045690pfd.3.2016.12.01.10.06.21; Thu, 01 Dec 2016 10:06:21 -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 S1758130AbcLASGQ (ORCPT + 25 others); Thu, 1 Dec 2016 13:06:16 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:60193 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759558AbcLASDB (ORCPT ); Thu, 1 Dec 2016 13:03:01 -0500 Received: from 177-59-7-93.3g.claro.net.br ([177.59.7.93] helo=jouet.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.85_2 #1 (Red Hat Linux)) id 1cCVh4-0006s1-QC; Thu, 01 Dec 2016 18:02:51 +0000 Received: by jouet.infradead.org (Postfix, from userid 1000) id 7B629140500; Thu, 1 Dec 2016 15:02:36 -0300 (BRT) From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, Wang Nan , He Kuang , Joe Stringer , Zefan Li , pi3orama@163.com, Arnaldo Carvalho de Melo Subject: [PATCH 06/19] tools lib bpf: Add private field for bpf_object Date: Thu, 1 Dec 2016 15:02:22 -0300 Message-Id: <20161201180235.18392-7-acme@kernel.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161201180235.18392-1-acme@kernel.org> References: <20161201180235.18392-1-acme@kernel.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wang Nan Similar to other classes defined in libbpf.h (map and program), allow 'object' class has its own private data. Signed-off-by: Wang Nan Acked-by: Alexei Starovoitov Cc: He Kuang Cc: Joe Stringer Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/20161126070354.141764-3-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/bpf/libbpf.c | 23 +++++++++++++++++++++++ tools/lib/bpf/libbpf.h | 5 +++++ 2 files changed, 28 insertions(+) -- 2.9.3 diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 96a2b2ff1212..866d5cdeffc7 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -229,6 +229,10 @@ struct bpf_object { * all objects. */ struct list_head list; + + void *priv; + bpf_object_clear_priv_t clear_priv; + char path[]; }; #define obj_elf_valid(o) ((o)->efile.elf) @@ -1229,6 +1233,9 @@ void bpf_object__close(struct bpf_object *obj) if (!obj) return; + if (obj->clear_priv) + obj->clear_priv(obj, obj->priv); + bpf_object__elf_finish(obj); bpf_object__unload(obj); @@ -1282,6 +1289,22 @@ unsigned int bpf_object__kversion(struct bpf_object *obj) return obj ? obj->kern_version : 0; } +int bpf_object__set_priv(struct bpf_object *obj, void *priv, + bpf_object_clear_priv_t clear_priv) +{ + if (obj->priv && obj->clear_priv) + obj->clear_priv(obj, obj->priv); + + obj->priv = priv; + obj->clear_priv = clear_priv; + return 0; +} + +void *bpf_object__priv(struct bpf_object *obj) +{ + return obj ? obj->priv : ERR_PTR(-EINVAL); +} + 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 dd7a513efb10..0c0b0127e03e 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -79,6 +79,11 @@ struct bpf_object *bpf_object__next(struct bpf_object *prev); (pos) != NULL; \ (pos) = (tmp), (tmp) = bpf_object__next(tmp)) +typedef void (*bpf_object_clear_priv_t)(struct bpf_object *, void *); +int bpf_object__set_priv(struct bpf_object *obj, void *priv, + bpf_object_clear_priv_t clear_priv); +void *bpf_object__priv(struct bpf_object *prog); + /* Accessors of bpf_program. */ struct bpf_program; struct bpf_program *bpf_program__next(struct bpf_program *prog,