From patchwork Fri Nov 9 00:22:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 10675171 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 0C9B31057 for ; Fri, 9 Nov 2018 00:22:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F209F2E936 for ; Fri, 9 Nov 2018 00:22:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E53642E950; Fri, 9 Nov 2018 00:22:28 +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 78F142E91A for ; Fri, 9 Nov 2018 00:22:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727742AbeKIKA2 (ORCPT ); Fri, 9 Nov 2018 05:00:28 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:43291 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727718AbeKIKA2 (ORCPT ); Fri, 9 Nov 2018 05:00:28 -0500 Received: by mail-pl1-f195.google.com with SMTP id g59-v6so55895plb.10 for ; Thu, 08 Nov 2018 16:22:24 -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=YQgFM6EgajjoaTM392UrTbkvh275AydndcKVjYWUaAM=; b=MB45Jszh9IHvOZgzFmQzbQDjXzkUPei6XEjX7RexpCg4EAqOnQB4jEamOi2WDsB2uJ qtYjXO5CUuWBG178mBL5flQ0jzVMqZSQsMNsBa4jw4D80Wz/wrdi60RxgkrlOU8SuLrC sD4V83EipbisWK2cG40UHSqOE31ruEhNlUkXe+q6ydFNhHbLMC+RdhcB17kHkcJNcMo9 OJ15vzfZ66Qn+t8sxKia8tHQjSu3nst+7wvjXPoMbu9L8GJdZvHdjnCbBMA7TLu4dC7s n6ZAj+hc9G1/6e7BGk5VjSP+dVJuHerLEl9IPxTok6NCOeYgf40l7aVXdxhPwyP8OiAk 1cBA== 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=YQgFM6EgajjoaTM392UrTbkvh275AydndcKVjYWUaAM=; b=GCR6pZXhLH9AAIaJM4LhrX0tv4lqAeslEFhiowRCvC7Ddu9eKz2+0l0mBsuyfTeL8t Hi8JX142T9fF2d/k/P9K2roGnuHpjUNXIchYAlgfjOTdBfbBnhRxl/lgICbQhZLM9qGT TG47kN+iOtEBR3QYLVtiMGRgLBh5i2TQ/V8fVihoHk2Njaq85yi3xHF8h6MPm1XkKKFw oQmuNpQpp5rY34Vcxq12ZWUU1w7Lu9Y9BbybFieYK8VlHpYq4/VQ3OUnob5PnQWH2HhK kxgYXHYIym9GvhCYjMsWbHxhM3vy+CPAiNVB5l6F/8ZdNlSAkxIzEndYFu2GbhBbV2zA OiIw== X-Gm-Message-State: AGRZ1gJxTKbKRFr3RgSWGc/66ayI/FyQaDJRIsPoTali+G6M8ppeG+Lu m9XkYbd2waWW7vBDxfFcajJ4sg== X-Google-Smtp-Source: AJdET5ejSTbPEh4n/GtI4q3ISSwwaLzZRfBNtKHsB+Q93o/7tDbPVYC6y+DS+z9hPWjRklQcsXE+wg== X-Received: by 2002:a17:902:8f94:: with SMTP id z20-v6mr6571127plo.175.1541722944160; Thu, 08 Nov 2018 16:22:24 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 16:22:23 -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 4/7] libbpf: add internal pin_name Date: Thu, 8 Nov 2018 16:22:10 -0800 Message-Id: <20181109002213.5914-5-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 pin_name is the same as section_name where '/' is replaced by '_'. bpf_object__pin_programs is converted to use pin_name to avoid the situation where section_name would require creating another subdirectory for a pin (as, for example, when calling bpf_object__pin_programs for programs in sections like "cgroup/connect6"). Signed-off-by: Stanislav Fomichev --- tools/lib/bpf/libbpf.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index cfa269c91e11..38dbeb113eeb 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -124,6 +124,10 @@ struct bpf_program { char *name; int prog_ifindex; char *section_name; + /* section_name with / replaced by _; makes recursive pinning + * in bpf_object__pin_programs easier + */ + char *pin_name; struct bpf_insn *insns; size_t insns_cnt, main_prog_cnt; enum bpf_prog_type type; @@ -253,6 +257,7 @@ static void bpf_program__exit(struct bpf_program *prog) bpf_program__unload(prog); zfree(&prog->name); zfree(&prog->section_name); + zfree(&prog->pin_name); zfree(&prog->insns); zfree(&prog->reloc_desc); @@ -261,6 +266,18 @@ static void bpf_program__exit(struct bpf_program *prog) prog->idx = -1; } +static char *__bpf_program__pin_name(struct bpf_program *prog) +{ + char *name; + + name = strdup(prog->section_name); + for (char *p = name; p && *p; p++) + if (*p == '/') + *p = '_'; + + return name; +} + static int bpf_program__init(void *data, size_t size, char *section_name, int idx, struct bpf_program *prog) @@ -279,6 +296,13 @@ bpf_program__init(void *data, size_t size, char *section_name, int idx, goto errout; } + prog->pin_name = __bpf_program__pin_name(prog); + if (!prog->pin_name) { + pr_warning("failed to alloc pin name for prog under section(%d) %s\n", + idx, section_name); + goto errout; + } + prog->insns = malloc(size); if (!prog->insns) { pr_warning("failed to alloc insns for prog under section %s\n", @@ -2008,7 +2032,7 @@ int bpf_object__pin_programs(struct bpf_object *obj, const char *path) int len; len = snprintf(buf, PATH_MAX, "%s/%s", path, - prog->section_name); + prog->pin_name); if (len < 0) { err = -EINVAL; goto err_unpin_programs; @@ -2032,7 +2056,7 @@ int bpf_object__pin_programs(struct bpf_object *obj, const char *path) int len; len = snprintf(buf, PATH_MAX, "%s/%s", path, - prog->section_name); + prog->pin_name); if (len < 0) continue; else if (len >= PATH_MAX) @@ -2057,7 +2081,7 @@ int bpf_object__unpin_programs(struct bpf_object *obj, const char *path) int len; len = snprintf(buf, PATH_MAX, "%s/%s", path, - prog->section_name); + prog->pin_name); if (len < 0) return -EINVAL; else if (len >= PATH_MAX)