Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3443975pxa; Tue, 25 Aug 2020 23:52:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypKIvFiylxohZ8COMg5UyzRGDdadpMgSl58wFHAzeMzAAxkF9y4nqd2T6GbqA37YPjGvcr X-Received: by 2002:a17:907:2805:: with SMTP id eb5mr15042930ejc.254.1598424723097; Tue, 25 Aug 2020 23:52:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598424723; cv=none; d=google.com; s=arc-20160816; b=IoemrY7N/1VSB9bUbPiI3DwCB8aR2pVpEP0Q4Tbq5WkCAPPg9k+C0DDY9Rw6zqakj3 nuYOIqYwrFn1af/LUQFxJSHthr26/dEZHI+UiF0jzsA4SIDG8ZtVtek4Ar/vbflWiN5q 7BtDibnKDfT5w3c2jFjYb2dAzXlQMPhKbCKgwVdbilf3DbSl8nF49UXMb75DgNdqlp5x tWC+HvnNJe9GYdFOgk27gnLiNE4+cN4HzwNqlEc/Z7P0QZMvt3oCww3h6hYlHaOvwbe9 QykoNYTHMJC7M3+3p2OZyARIHIn8k2lVEkRYq0r/kSWqieuaKXSS+JThebrL1g2ZUUfk /kTg== 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=z8bYioKTAu+DXMBCJGN6zlrMSBVFyPMVFFEmATTqveo=; b=ONk2OyTyRNN7l9DCsD+Ysi8M2uw3f4v2Of9SoYZAwO1I7rHz0DDCfcCa0LhVt6Jl22 lVZ9yGE0Be+t3HeRnntqo4UGj8IBPM3mVChMocKZFotkUyIoO/XUNmSJMdWSARIZKge/ A73Xho52et9dX2FeRtwz90Ree1pbXIbAEHnV+i6Bh1WBcSDZZRDvz8IYe2QC2vv9eHrA p1et6UtPN4eFIqomOz4OHcR8Mo/PK68LF8MS3XjkiI5IsbZPlxuw6uIHEJ99KPGIgtVC z1sOWR99DzuMTa1AGObiGG6DqMdz+xxAKNOsRfT4BHuw7hyx+FhiOaGWeZeMwGM5bflS nHEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=I9dwFc3C; 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 s2si984140ejs.269.2020.08.25.23.51.40; Tue, 25 Aug 2020 23:52:03 -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=I9dwFc3C; 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 S1726779AbgHZGvI (ORCPT + 99 others); Wed, 26 Aug 2020 02:51:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726233AbgHZGvG (ORCPT ); Wed, 26 Aug 2020 02:51:06 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 216B2C061574; Tue, 25 Aug 2020 23:51:06 -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=z8bYioKTAu+DXMBCJGN6zlrMSBVFyPMVFFEmATTqveo=; b=I9dwFc3CSg6r0tD6T7+Lr5NADK XLpgXplCt9HJKZljg48ugPO4zz2Xwhva2w/QMVi04aoKXms2AXSIAc7VacbKgl9dtfabMGFyCsXf9 2/BCbN9iM1EmFVTMLGHOuxHy11ERMAE9TtOEZAozSzKuGVe/bOkJUi02aGp6qHOa/71xedmoIa9wW GgBLpS/QG4fAQBy5w5fRTL41gljBGVzdbXCdkrshwwbo74+KhH4oYPKvPrQqXFpQiCDxomzCOw6EM P39rMhhLsvqC4/mQ0boFXSoPFI2eD2Rx8vjGwWvDC4l3petTknzDOnz1ecvGJS6KsIGkBs6+Uoqfp cPNdJlDg==; 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 1kApGv-0003DV-CF; Wed, 26 Aug 2020 06:51:01 +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 11/19] loop: use __register_blkdev to allocate devices on demand Date: Wed, 26 Aug 2020 08:24:38 +0200 Message-Id: <20200826062446.31860-12-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 Use the simpler mechanism attached to major_name to allocate a brd device when a currently unregistered minor is accessed. Signed-off-by: Christoph Hellwig --- drivers/block/loop.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 5a991510136225..7c944a425f718f 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -2234,24 +2234,18 @@ static int loop_lookup(struct loop_device **l, int i) return ret; } -static struct kobject *loop_probe(dev_t dev, int *part, void *data) +static void loop_probe(dev_t dev) { + int idx = MINOR(dev) >> part_shift; struct loop_device *lo; - struct kobject *kobj; - int err; + + if (max_loop && idx >= max_loop) + return; mutex_lock(&loop_ctl_mutex); - err = loop_lookup(&lo, MINOR(dev) >> part_shift); - if (err < 0) - err = loop_add(&lo, MINOR(dev) >> part_shift); - if (err < 0) - kobj = NULL; - else - kobj = get_disk_and_module(lo->lo_disk); + if (loop_lookup(&lo, idx) < 0) + loop_add(&lo, idx); mutex_unlock(&loop_ctl_mutex); - - *part = 0; - return kobj; } static long loop_control_ioctl(struct file *file, unsigned int cmd, @@ -2371,14 +2365,11 @@ static int __init loop_init(void) goto err_out; - if (register_blkdev(LOOP_MAJOR, "loop")) { + if (__register_blkdev(LOOP_MAJOR, "loop", loop_probe)) { err = -EIO; goto misc_out; } - blk_register_region(MKDEV(LOOP_MAJOR, 0), range, - THIS_MODULE, loop_probe, NULL, NULL); - /* pre-create number of devices given by config or max_loop */ mutex_lock(&loop_ctl_mutex); for (i = 0; i < nr; i++) @@ -2404,16 +2395,11 @@ static int loop_exit_cb(int id, void *ptr, void *data) static void __exit loop_exit(void) { - unsigned long range; - - range = max_loop ? max_loop << part_shift : 1UL << MINORBITS; - mutex_lock(&loop_ctl_mutex); idr_for_each(&loop_index_idr, &loop_exit_cb, NULL); idr_destroy(&loop_index_idr); - blk_unregister_region(MKDEV(LOOP_MAJOR, 0), range); unregister_blkdev(LOOP_MAJOR, "loop"); misc_deregister(&loop_misc); -- 2.28.0