Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3440691pxa; Tue, 25 Aug 2020 23:43:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+dr1Skv/l4sOu+GIHNTJpKaNhTOK2exa6ANXLkXA28lgQTBK7sCazfKv+7fQYVeHX4GMv X-Received: by 2002:a17:906:8403:: with SMTP id n3mr8918430ejx.443.1598424191230; Tue, 25 Aug 2020 23:43:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598424191; cv=none; d=google.com; s=arc-20160816; b=RZocfwVtu99XmLkiOY3lfrOxzSRZy5HYaVbgw/N2tx1TZq7BYUA68jczqSyBBDA13m rbicIFkfS9lGF2eM2q0QD6VVfREenNvZmm1pRc/bxGEHTVvuNcyrESrEuJ+s6byvTKD/ V6K/+9lCNeHCVlJF7vWu/au7XYN1oNnVrkJwjUKyV4jVLPIC9cDHiLXK1uD5378IohIx 53hE8Q/yBWEkT8OfuuTwxEyXjWxyXlFcWkqkVACW9nQJB9etwomZbGn0XB0XEZPednp0 Rz7Vx8WgGYDAKYCf/lwpJvPoTFlHNxf7LBZe3WfHTZsbmlIgRd8HMpL4p+nqpYRYz1Z0 HHUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4xtHD/LVW7syPOvnagl2eLkMWsDcdFz+dmbJvQXXE2U=; b=lpyhP+AUr0u55y6TJbV+c3lJhrD+iKqMa3IsLr1/S5SDPrSXvMgHgpsulqemzlciOY Nri/XUmviT9KmXdTxvWM/b9hoR9bkBWmvUO5sUa8LXX/cqPxNkDVrdPkYLhIvxNvPFis AO7mnuznHWZqH4Qox30ZyGFSaN0ersWd8EdReBzWB5gIzErESKv5W8V2XoOeIfZOrCpn mQTI3xmX8cwjhDN8phj4lXwmiU3a+1yFtLH425Wo83+InnHAfr/vtm70hi1pZ6sKJZZ9 SlwugrTmx9+MUFpc7v+0GzRmj7zyfCw7NRmy1IpkPbliLk9uL2r42fgOAz/4M4uzL9iO WnBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=eKbMFYls; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j7si1149591ejo.167.2020.08.25.23.42.48; Tue, 25 Aug 2020 23:43:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=eKbMFYls; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726779AbgHZGkK (ORCPT + 99 others); Wed, 26 Aug 2020 02:40:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726039AbgHZGkK (ORCPT ); Wed, 26 Aug 2020 02:40:10 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEE31C061574; Tue, 25 Aug 2020 23:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=4xtHD/LVW7syPOvnagl2eLkMWsDcdFz+dmbJvQXXE2U=; b=eKbMFYlsgUXM0fA+NiB4PhHzGb wrwkZXLtQYgaC1ka++8b3rG5Ue12E5ZRmL1ffxpGi9oAkm/0ka6fDZIjr+EDLwY4uYWbTLLhMdOLd DOlU+kA364l0BcQnT7ejGZupP7jzMKNi0pinAwP81/TWsS/qPzKHeVJJ8pDPkGIXbjvn4pNCc6j/E bxFWYccnzK/dA6Ywg51oO5eIiSxbAwnMhLVMEwWWm5torWykSQxiHhv6EDYkPaaYL2PvvbA8jYAHP DahlR+jEIZaga/nYBefsNQGVwWP9NU2Krc44s8y50KEKXnCc8LRV8WyG72QyDAUnss8wWUeACsx3Z QvermOUw==; Received: from 213-225-6-196.nat.highway.a1.net ([213.225.6.196] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAp6J-0002Cr-VJ; Wed, 26 Aug 2020 06:40:04 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Denis Efremov , "David S. Miller" , Song Liu , Al Viro , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org, linux-raid@vger.kernel.org, linux-scsi@vger.kernel.org, linux-m68k@lists.linux-m68k.org Subject: [PATCH 06/19] block: add an optional probe callback to major_names Date: Wed, 26 Aug 2020 08:24:33 +0200 Message-Id: <20200826062446.31860-7-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200826062446.31860-1-hch@lst.de> References: <20200826062446.31860-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.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 Add a callback to the major_names array that allows a driver to override how to probe for dev_t that doesn't currently have a gendisk registered. This will help separating the lookup of the gendisk by dev_t vs probe action for a not currently registered dev_t. Signed-off-by: Christoph Hellwig --- block/genhd.c | 21 ++++++++++++++++++--- include/linux/genhd.h | 5 ++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index 00164304317cfa..4cbeff3ec1ef5a 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -402,6 +402,7 @@ static struct blk_major_name { struct blk_major_name *next; int major; char name[16]; + void (*probe)(dev_t devt); } *major_names[BLKDEV_MAJOR_HASH_SIZE]; static DEFINE_MUTEX(major_names_lock); @@ -444,7 +445,8 @@ void blkdev_show(struct seq_file *seqf, off_t offset) * See Documentation/admin-guide/devices.txt for the list of allocated * major numbers. */ -int register_blkdev(unsigned int major, const char *name) +int __register_blkdev(unsigned int major, const char *name, + void (*probe)(dev_t devt)) { struct blk_major_name **n, *p; int index, ret = 0; @@ -483,6 +485,7 @@ int register_blkdev(unsigned int major, const char *name) } p->major = major; + p->probe = probe; strlcpy(p->name, name, sizeof(p->name)); p->next = NULL; index = major_to_index(major); @@ -505,8 +508,7 @@ int register_blkdev(unsigned int major, const char *name) mutex_unlock(&major_names_lock); return ret; } - -EXPORT_SYMBOL(register_blkdev); +EXPORT_SYMBOL(__register_blkdev); void unregister_blkdev(unsigned int major, const char *name) { @@ -1037,6 +1039,19 @@ static ssize_t disk_badblocks_store(struct device *dev, static void request_gendisk_module(dev_t devt) { + unsigned int major = MAJOR(devt); + struct blk_major_name **n; + + mutex_lock(&major_names_lock); + for (n = &major_names[major_to_index(major)]; *n; n = &(*n)->next) { + if ((*n)->major == major && (*n)->probe) { + (*n)->probe(devt); + mutex_unlock(&major_names_lock); + return; + } + } + mutex_unlock(&major_names_lock); + if (request_module("block-major-%d-%d", MAJOR(devt), MINOR(devt)) > 0) /* Make old-style 2.4 aliases work */ request_module("block-major-%d", MAJOR(devt)); diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 4ab853461dff25..c0bde190a3dd0c 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -369,7 +369,10 @@ extern void blk_unregister_region(dev_t devt, unsigned long range); #define alloc_disk(minors) alloc_disk_node(minors, NUMA_NO_NODE) -int register_blkdev(unsigned int major, const char *name); +int __register_blkdev(unsigned int major, const char *name, + void (*probe)(dev_t devt)); +#define register_blkdev(major, name) \ + __register_blkdev(major, name, NULL) void unregister_blkdev(unsigned int major, const char *name); int revalidate_disk(struct gendisk *disk); -- 2.28.0