From patchwork Mon Nov 12 09:56:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 10678415 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 7A53B14BA for ; Mon, 12 Nov 2018 09:58:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 658F829F62 for ; Mon, 12 Nov 2018 09:58:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 564E729F64; Mon, 12 Nov 2018 09:58:25 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 E931629F62 for ; Mon, 12 Nov 2018 09:58:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728273AbeKLTtf (ORCPT ); Mon, 12 Nov 2018 14:49:35 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:51439 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728236AbeKLTte (ORCPT ); Mon, 12 Nov 2018 14:49:34 -0500 Received: by mail-wm1-f68.google.com with SMTP id w7-v6so7803770wmc.1 for ; Mon, 12 Nov 2018 01:57:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gEkvf3D0ybtQ1XCiNuNOR20e0/KEmaDMFTtp87FuqbE=; b=N8KkHvWqCG3FPBQKMMKSv7Pg/NLzZZA7xMvcJW6U01Wj0GNYTuJeCcya4ODW4IlfDY bjeINPfviBlUjWGw0A/F1Z2j5xFDixkEn+Wq8pjVDa2f0IyCUhwOwJnWnNFIaWBeVVTq d85CwbZ1TDnYV7195SRPVFTFCEtIMsDAzsBRA= 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; bh=gEkvf3D0ybtQ1XCiNuNOR20e0/KEmaDMFTtp87FuqbE=; b=Yl1kTcAqxrANG3X0s9p5485E9iu6jI1PEjqUCkzDvRfrZ3/S1zElXHdcSwc8iNj7M4 EN6GeL/Rw4uXfIj3OxOvZ61w7+V1jCO+dp2Vh7b2mN6IPQke1qjLPLx4v0HGahp0N3im YxkIz8gi3JdJvetz3rEQThZAnSGx9VhnBBeKvmLygz0++BJwWojup3oN7kyqUKZdI94x 5ANWFbj/BmifEyNUV3OmLVZvw9vAJdIoTe3BXRfJHctcsUZ3Z5luT0P654cUvaVDmrEJ cszD3LEUzUh35jkFNkDjmdDCAjdEkSeKa/aOicyPeF/fYRJGHKjTY16QER1CBRTtWWKh /Ygg== X-Gm-Message-State: AGRZ1gKdKLcKOd/qjtTytjEol1g5sKDFtP44XBB0E7iihQZtOqoM17BL iVGDYKYYQoihsPquIS3lZODubw== X-Google-Smtp-Source: AJdET5fmKdDKURgKcd0/zNKsqHAs7FIXT38LFwZ+xmQ+O0/jj39RrDDpR/i7+8aP1nLdD0FN0ceDXg== X-Received: by 2002:a1c:3954:: with SMTP id g81-v6mr6728831wma.139.1542016624983; Mon, 12 Nov 2018 01:57:04 -0800 (PST) Received: from localhost.localdomain ([93.68.220.21]) by smtp.gmail.com with ESMTPSA id r14-v6sm21273089wro.8.2018.11.12.01.57.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 01:57:04 -0800 (PST) From: Paolo Valente To: Jens Axboe , Greg Kroah-Hartman , Tejun Heo , Li Zefan , Angelo Ruocco , Dennis Zhou , Josef Bacik , Liu Bo , Bart Van Assche , Johannes Weiner Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, ulf.hansson@linaro.org, linus.walleij@linaro.org, broonie@kernel.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, Jonathan Corbet , Paolo Valente Subject: [PATCH 01/12] kernfs: add function to find kernfs_node without increasing ref counter Date: Mon, 12 Nov 2018 10:56:21 +0100 Message-Id: <20181112095632.69114-2-paolo.valente@linaro.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20181112095632.69114-1-paolo.valente@linaro.org> References: <20181112095632.69114-1-paolo.valente@linaro.org> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Angelo Ruocco The kernfs pseudo file system doesn't export any function to only find a node by name, without also getting a reference on it. But in some cases it is useful to just locate a kernfs node, while using it or not depends on some other condition. This commit adds a function to just look for a node, without getting a reference on it. Signed-off-by: Angelo Ruocco Signed-off-by: Paolo Valente --- fs/kernfs/dir.c | 13 +++++++++++++ include/linux/kernfs.h | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 4ca0b5c18192..0003c665869d 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -892,6 +892,19 @@ static struct kernfs_node *kernfs_walk_ns(struct kernfs_node *parent, return parent; } +struct kernfs_node *kernfs_find(struct kernfs_node *parent, + const unsigned char *name) +{ + struct kernfs_node *kn; + + mutex_lock(&kernfs_mutex); + kn = kernfs_find_ns(parent, name, NULL); + mutex_unlock(&kernfs_mutex); + + return kn; +} +EXPORT_SYMBOL_GPL(kernfs_find); + /** * kernfs_find_and_get_ns - find and get kernfs_node with the given name * @parent: kernfs_node to search under diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h index 5b36b1287a5a..26e69d285964 100644 --- a/include/linux/kernfs.h +++ b/include/linux/kernfs.h @@ -309,6 +309,8 @@ void pr_cont_kernfs_path(struct kernfs_node *kn); struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn); struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent, const char *name, const void *ns); +struct kernfs_node *kernfs_find(struct kernfs_node *parent, + const unsigned char *name); struct kernfs_node *kernfs_walk_and_get_ns(struct kernfs_node *parent, const char *path, const void *ns); void kernfs_get(struct kernfs_node *kn); @@ -391,6 +393,11 @@ static inline struct kernfs_node * kernfs_find_and_get_ns(struct kernfs_node *parent, const char *name, const void *ns) { return NULL; } + +static inline struct kernfs_node * +kernfs_find(struct kernfs_node *parent, const char *name) +{ return NULL; } + static inline struct kernfs_node * kernfs_walk_and_get_ns(struct kernfs_node *parent, const char *path, const void *ns)