From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751294AbdAYBFs (ORCPT ); Tue, 24 Jan 2017 20:05:48 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:41831 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751218AbdAYBFj (ORCPT ); Tue, 24 Jan 2017 20:05:39 -0500 Subject: Re: [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin() To: Joe Stringer , References: <20170123011128.26534-1-joe@ovn.org> <20170123011128.26534-6-joe@ovn.org> CC: , , , From: "Wangnan (F)" Message-ID: Date: Wed, 25 Jan 2017 09:04:16 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <20170123011128.26534-6-joe@ovn.org> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.111.194.139] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.5887F99E.02AD,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: ed55e10fe495adb0eb75dc835ad2125c Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2017/1/23 9:11, Joe Stringer wrote: > Add a new API to pin a BPF program to the filesystem. The user can > specify the path full path within a BPF filesystem to pin the program. > Programs with multiple instances are pinned as 'foo', 'foo_1', 'foo_2', > and so on. > > Signed-off-by: Joe Stringer > --- > v2: Don't automount BPF filesystem > Split program, map, object pinning into separate APIs and separate > patches. > --- > tools/lib/bpf/libbpf.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ > tools/lib/bpf/libbpf.h | 1 + > 2 files changed, 77 insertions(+) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index e6cd62b1264b..eea5c74808f7 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -4,6 +4,7 @@ > * Copyright (C) 2013-2015 Alexei Starovoitov > * Copyright (C) 2015 Wang Nan > * Copyright (C) 2015 Huawei Inc. > + * Copyright (C) 2017 Nicira, Inc. > * > * This program is free software; you can redistribute it and/or > * modify it under the terms of the GNU Lesser General Public > @@ -22,6 +23,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -31,7 +33,10 @@ > #include > #include > #include > +#include > #include > +#include > +#include > #include > #include > > @@ -1237,6 +1242,77 @@ int bpf_object__load(struct bpf_object *obj) > return err; > } > > +static int check_path(const char *path) > +{ > + struct statfs st_fs; > + char *dname, *dir; > + int err = 0; > + > + if (path == NULL) > + return -EINVAL; > + > + dname = strdup(path); > + dir = dirname(dname); > + if (statfs(dir, &st_fs)) { > + pr_warning("failed to statfs %s: %s\n", dir, strerror(errno)); > + err = -errno; > + } > + free(dname); > + > + if (!err && st_fs.f_type != BPF_FS_MAGIC) { > + pr_warning("specified path %s is not on BPF FS\n", path); > + err = -EINVAL; > + } > + > + return err; > +} > + > +int bpf_program__pin(struct bpf_program *prog, const char *path) In your next patch please let caller select one instance: int bpf_program__pin(struct bpf_program *prog, int instance, const char *path) (please choose a better name) Then your can wrap it with another function to pin all instances, implement naming schema (%s_%d) there. Then implement naming schema in bpf_object__pin like: %s/objectname_mapname %s/objectname_progname_%d and make a bpf_{map,program}__pin the raw pinning functions with no naming schema. Thank you.