From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F538C4320A for ; Thu, 19 Aug 2021 02:51:49 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 35CDC610FE for ; Thu, 19 Aug 2021 02:51:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 35CDC610FE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94.2) (envelope-from ) id 1mGY9j-0007Ae-OX; Wed, 18 Aug 2021 22:51:47 -0400 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1mGY94-0005Pu-Mb for kernelnewbies@kernelnewbies.org; Wed, 18 Aug 2021 22:51:06 -0400 Received: by mail-ot1-x336.google.com with SMTP id v33-20020a0568300921b0290517cd06302dso6810142ott.13 for ; Wed, 18 Aug 2021 19:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VB+baDa9o7QBYGGk/mOq5L0ZVoeaDiRYIRcxi/hAPFM=; b=WCUXl+XhEcacaKGATrA0KhVNljLVCbZOhtVf4LLxwbgmArictmIyRRaV3cK3TnyIKM Qwo+vhcXG9tDKAhK+UHDSTI6KaRjNFEsDSG6SxnrfM3Cdy5/BHSrB/Ys67uMO6a7mPaE LBNPtjEPEIs8k0xr+vynoknFYsdSCNSEFEB872mk72bjjOAuwCuEH1VbMS5Qzv0U43Lv HkOAo4UeJ/lpKS+vu3oS7ZU0Ek351ZtjkspNE32IXc7s6Yi0JbZmRa/yaYd+tv/ZFUqF qlh4qZ9Rc+7HOja0yjtE4gJpKQl22gkLQ7C036FjyuDMvGYv2/3f/2w02xWUxBJC/OkK 2sdg== 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=VB+baDa9o7QBYGGk/mOq5L0ZVoeaDiRYIRcxi/hAPFM=; b=Pi3d2pha3yVgxZjZod3Hyj76DyBfIjpGIB9U7uBfzrIxW9U6Ryqj09MHzgfh9vo+ux az0xR/PutRIgph94Yct3dlfwb5WlOxVWo33tOSz9GYS1xtxWBWY93WEC/L0Ls7D+Lqmt JoihMYM0+u4aJga6xPQnwEAqsymP8uO1yB2dskQEynwpuaRZwoMbyT6iFunukz2CJK9l C29RuNc9B0bf2qykgp2a7tjDyRYxGxCQ7aKCSecOCV+/55sJrS+plK0ZhbTnlSTFmZTP 619worxAx8X/2a2578Bf78NGuzmaDQJX8GYslmPz5qc432IKExXxX6x2lz8msqwcm04p B0NA== X-Gm-Message-State: AOAM532xoV+VRtfOo+j9DtJD3Z/k4Grax/Xiwo2Y3x6NFoVX1Jl/2ys3 RGqg6EFmmomT2I26IP2TCb4= X-Google-Smtp-Source: ABdhPJwoaFZji6/oDadqjC5RCzefm/AYQBsuP/lp5448Yd0r5LflzybTLSICxFXmrqu4zpxMmxjxQw== X-Received: by 2002:a05:6830:156:: with SMTP id j22mr1371657otp.75.1629341464884; Wed, 18 Aug 2021 19:51:04 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:04 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Subject: [RFC PATCH v3 02/18] block: Add get_disk_by_name() for use by blkdev LED trigger Date: Wed, 18 Aug 2021 21:50:37 -0500 Message-Id: <20210819025053.222710-3-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-1-arequipeno@gmail.com> MIME-Version: 1.0 Cc: axboe@kernel.dk, kabel@kernel.org, linux-kernel@vger.kernel.org, pavel@ucw.cz, kernelnewbies@kernelnewbies.org X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org Add API that gets a "handle" (pointer & incremented reference count) to a block device (struct gendisk) by name. Used by the block device LED trigger when configuring which device(s) an LED should monitor. Signed-off-by: Ian Pilcher --- block/genhd.c | 25 +++++++++++++++++++++++++ include/linux/genhd.h | 10 ++++++++++ 2 files changed, 35 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index 298ee78c1bda..e6d7bb709d62 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1362,3 +1362,28 @@ int bdev_read_only(struct block_device *bdev) return bdev->bd_read_only || get_disk_ro(bdev->bd_disk); } EXPORT_SYMBOL(bdev_read_only); + +static int match_disk_name(struct device *const dev, const void *const name) +{ + return dev->type == &disk_type + && strcmp(name, dev_to_disk(dev)->disk_name) == 0; +} + +/** + * get_disk_by_name - get a gendisk by name + * @name: the name of the disk + * + * Returns a pointer to the gendisk named @name (if it exists), @NULL if not. + * Increments the disk's reference count, so caller must call put_device(). + */ +struct gendisk *get_disk_by_name(const char *const name) +{ + struct device *dev; + + dev = class_find_device(&block_class, NULL, name, match_disk_name); + if (dev == NULL) + return NULL; + + return dev_to_disk(dev); +} +EXPORT_SYMBOL_GPL(get_disk_by_name); diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 13b34177cc85..b26bbf2d9048 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -342,4 +342,14 @@ static inline void printk_all_partitions(void) } #endif /* CONFIG_BLOCK */ +/* for blkdev LED trigger (drivers/leds/trigger/ledtrig-blkdev.c) */ +#ifdef CONFIG_BLOCK +struct gendisk *get_disk_by_name(const char *name); +#else +static inline struct gendisk *get_disk_by_name(const char *name) +{ + return NULL; +} +#endif + #endif /* _LINUX_GENHD_H */ -- 2.31.1 _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies